Discussion:
Class::Container by Ken Williams added to Catalog::lazy_loaders
Terrence Brannon
2005-01-25 23:36:29 UTC
Permalink
In reading the docs to Class::Container, I noticed that object
creation could be delayed. Hence is belongs in the list of
module/object lazy loaders. Here's the entry:

=item * Class::Container by Ken Williams

L<http://search.cpan.org/dist/Class-Container>

This module's primary purpose is to provide something similar to
Inversion of Control: the container establishes and provides the
dependencies of a class instead of the class doing so.

Inversion of Control is discussed here:

L<http://www.picocontainer.org/Inversion+of+Control>
--
Carter's Compass: I know I'm on the right track when,
by deleting something, I'm adding functionality.
Stevan Little
2005-01-26 01:27:40 UTC
Permalink
Terrance,

If you are going to include classes which are not just specifically
lazy loaders, then you can also include IOC::Service which has the
deferred() method which will create an IOC::Service::Deferred object
for you. IOC::Service::Deferred objects cannot be instantiated
directly, only through the IOC::Service object (it checks the caller
and throws an exception if not called from within an IOC::Service
object). Basic usage of it would be:

my $container = IOC::Container->new('DBI');
# create the dsn, username and password services here
# and put them in the container
my $service = IOC::Service->new('connection' => sub {
my $c = shift;
DBI->connect($c->get('dsn'), $c->get('username'), $c->get('password'));
});
$container->register($service);

my $dbh = $service->deferred();

Now the moment anyone uses $dbh, it will resolve the service. You can
also use IOC::Service::ConstructorInjection,
IOC::Service::SetterInjection, IOC::Service::Prototype,
IOC::Service::Prototype::ConstructorInjection and
IOC::Service::Prototype::SetterInjection in this way as well.

However it should be noted that this feature was never really intended
to be used directly (hence it's ackward usage), and was only meant as a
means of allowing for circular dependencies in the IOC framework, so
you cannot directly instantiate an IOC::Service::Deferred object
through an IOC::Container (containers hold services), you must retain
the reference to the IOC::Service itself to get the deferred instance.

Also the code is based heavily on Class::LazyLoad which Rob Kinyon and
I worked on, which is a much better general purpose lazy loader.

Steve
Post by Terrence Brannon
In reading the docs to Class::Container, I noticed that object
creation could be delayed. Hence is belongs in the list of
=item * Class::Container by Ken Williams
L<http://search.cpan.org/dist/Class-Container>
This module's primary purpose is to provide something similar to
Inversion of Control: the container establishes and provides the
dependencies of a class instead of the class doing so.
L<http://www.picocontainer.org/Inversion+of+Control>
--
Carter's Compass: I know I'm on the right track when,
by deleting something, I'm adding functionality.
_______________________________________________
sw-design mailing list
http://metaperl.com/cgi-bin/mailman/listinfo/sw-design
b***@metaperl.com
2005-01-26 18:40:32 UTC
Permalink
Post by Stevan Little
Terrance,
If you are going to include classes which are not just specifically
lazy loaders, then you can also include IOC::Service
added. I moved Ken's module and yours to a section titled "MODULES
WITH A LARGER PURPOSE":

http://www.metaperl.com/article-pod/Catalog-lazy_loaders/lazy_loaders.html
--
Carter's Compass: I know I'm on the right track when,
by deleting something, I'm adding functionality.
Loading...