Pickles::Container - A Simple Container
package MyApp::Container; use base qw(Pickles::Container); # somewhere else in your code my $c = MyApp::Container->new(); # a persistent object (lasts during this process) my $object = Foo->new(); $c->register( foo => $object ); # a per-instance object (lasts only during an instance of # this container is alive) $c->register( bar => sub { Bar->new } ); # a persistent object, lazily instantiated $c->register( baz => sub { Baz->new }, { persistent => 1 } ); { my $guard = $c->new_scope; my $foo = $c->get('foo'); my $bar = $c->get('bar'); my $baz = $c->get('baz'); # $guard goes out of scope } { my $guard = $c->new_scope; my $foo = $c->get('foo'); # Same as previous $foo my $bar = $c->get('bar'); # DIFFERENT from previous $bar my $baz = $c->get('baz'); # Same as previous $baz }
Pickles::Container is a simple container object like Object::Container.
The main difference is that it has per-process lifecycle and per-instance lifecycle objects.
To install Pickles, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pickles
CPAN shell
perl -MCPAN -e shell install Pickles
For more information on module installation, please visit the detailed CPAN module installation guide.