GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  IOC::CONTAINER::METHODRESOLUTION (3)

.ds Aq ’

NAME

IOC::Container::MethodResolution - An IOC Container object which support method resolution of services

CONTENTS

SYNOPSIS



  use IOC::Container;
 
  my $container = IOC::Container->new();
  $container->register(IOC::Service::Literal->new(log_file => "logfile.log"));
  $container->register(IOC::Service->new(logger => sub {
      my $c = shift;
      return FileLogger->new($c->log_file());
  }));
  $container->register(IOC::Service->new(application => sub {
      my $c = shift;
      my $app = Application->new();
      $app->logger($c->logger());
      return $app;
  }));

  $container->application()->run();    
 
  # or a more complex example
  # utilizing a tree-like structure
  # of services

  my $logging = IOC::Container->new(logging);
  $logging->register(IOC::Service->new(logger => sub {
      my $c = shift;
      return My::FileLogger->new($c->root()->filesystem()->filemanager()->openFile($c->log_file()));
  }));
  $logging->register(IOC::Service::Literal->new(log_file => /var/my_app.log));
 
  my $database = IOC::Container->new(database);
  $database->register(IOC::Service->new(connection => sub {
      my $c = shift;
      return My::DB->connect($c->dsn(), $c->username(), $c->password());
  }));
  $database->register(IOC::Service::Literal->new(dsn      => dbi:mysql:my_app));
  $database->register(IOC::Service::Literal->new(username => test));
  $database->register(IOC::Service::Literal->new(password => secret_test));         
 
  my $file_system = IOC::Container->new(filesystem);
  $file_system->register(IOC::Service->new(filemanager => sub { return My::FileManager->new() }));
         
  my $container = IOC::Container->new();
  $container->addSubContainers($file_system, $database, $logging);
  $container->register(IOC::Service->new(application => sub {
      my $c = shift;
      my $app = My::Application->new();
      $app->logger($c->root()->logging()->logger());
      $app->db_connection($c->root()->database()->connection());
      return $app;
  }));
 
  $container->application()->run();



DESCRIPTION

In this IOC framework, the IOC::Container::MethodResolution object holds instances of keyed IOC::Service objects which can be called as methods.



            +----------------+
            | IOC::Container |
            +----------------+
                    |
                    ^
                    |
   +----------------------------------+
   | IOC::Container::MethodResolution |
   +----------------------------------+



METHODS

There are no new methods for this subclass, but when a service is registered, the name of the service becomes a valid method for this particular container instance.

TO DO

Work on the documentation

BUGS

None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.

CODE COVERAGE

I use <B>Devel::CoverB> to test the code coverage of my tests, see the CODE COVERAGE section of IOC for more information.

SEE ALSO

AUTHOR

stevan little, <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Copyright 2004-2007 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 IOC::CONTAINER::METHODRESOLUTION (3) 2007-04-22

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.