Micro::Container - Lite weight and inheritable object container
package MyContainer; use parent 'Micro::Container'; __PACKAGE__->register( JSON => [], ); package MyContainer::Child; use parent 'MyContainer'; __PACKAGE__->register( MessagePack => sub { my $c = shift; my $mp = $c->load_class('Data::MessagePack')->new; $mp->utf8; $mp; }, ); package main; use MyContainer::Child; my $container = MyContainer::Child->instance; say $container->get('JSON')->encode_json({ foo => 'bar' }); my $data = $container->get('MessagePack')->decode($message_pack_string);
Micro::Container is inheritable object container.
Returns instance.
package MyContainer; parent 'Micro::Container'; package main; use MyContainer; my $container = MyContainer->instance;
Register objects to container.
package MyContainer; parent 'Micro::Container'; __PACKAGE__->register( 'LWP::UserAgent' => [ agent => 'FooBar' ], JSON => sub { my $c = shift; $c->load_class('JSON')->new->utf8; }, );
Remove registered objects by name.
MyContainer->unregister('JSON', 'LWP::UserAgent');
Get registered method.
my $json = MyContainer->get('JSON');
Constructs a class name and require the class.
require
Taken from Plack::Util.
$class = MyContainer->load_class('Foo'); # Foo $class = MyContainer->load_class('Baz', 'Foo::Bar'); # Foo::Bar::Baz $class = MyContainer->load_class('+XYZ::ZZZ', 'Foo::Bar'); # XYZ::ZZZ
xaicron <xaicron@cpan.org>
Copyright 2013 - xaicron
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Object::Container.
Plack::Util.
To install Micro::Container, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Micro::Container
CPAN shell
perl -MCPAN -e shell install Micro::Container
For more information on module installation, please visit the detailed CPAN module installation guide.