Provided by: libobject-container-perl_0.14-1_all
NAME
Object::Container::ja - XXXXXXXXXXXXXXXXXXXXXX
SYNOPSIS
use Object::Container; ## OO XXXXXXX # XXX my $container = Object::Container->new; # XXXXXX $container->register('HTML::TreeBuilder'); # XXXXXXXXXXXXXXXXX $container->register('WWW::Mechanize', sub { my $mech = WWW::Mechanize->new( stack_depth => 1 ); $mech->agent_alias('Windows IE 6'); return $mech; }); # XXXXXXXXXXXXX my $mech = $container->get('WWW::Mechanize'); ## SingletonXXXXXXX my $container = Object::Container->instance; # SingletonXXXXXXXXXXXregister/getXXXXXXXXXXXXXXX Object::Container->register('WWW::Mechanize'); my $mech = Object::Container->get('WWW::Mechanize'); # SingletonXXXXXXXXgetXXXXXXXXXXXXXXXXXX use Object::Container 'container'; container->register('WWW::Mechanize'); my $mech = container->get('WWW::Mechanize'); my $mech = container('WWW::Mechanize'); # save as above # SingletonXXXXXXXXXXXXXX package MyObj; use Object::Container '-base'; register 'ua' => sub { LWP::UserAgent->new };
DESCRIPTION
Object::Container X Singleton XXXXXXXXOO XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXClass::Singleton XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Singleton XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX Object::Registrar XXXXXXXXXXXXXXXXOOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (XXXXXXXXXXXXXXX OOXXXXXXXXXSingletonXXXXXXXX XXXXXXXX OO XXXXXXXXX Singleton XXXXXXXXXXXXXXXXXXXXXXXXXX OOXXXXXXXX my $container = Object::Container->new; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX my $container1 = Object::Container->new; my $container2 = Object::Container->new; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SingletonXXXXXXXX my $container = Object::Container->instance; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SingletonXXXXXXXXXXXXXXXXregister X get XXXXX Object::Container->register('WWW::Mechanize', sub { WWW::Mechanize->new( stack_depth => 1 ) }); XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSingletonXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX MyContainer1->get('WWW::Mechanize'); MyContainer2->get('WWW::Mechanize'); XXXXXXXX SingletonXXXXXXXXEXPORTXX SingletonXXXXXXXXXXXXX MyContainer->get('WWW::Mechanize'); XXXXXXXXXXXXXXXXXXXXXXXXXXXXEXPORTXXXXXXXXXXXXXXX use MyContainer 'obj'; XXuse XXXXXXXXXXXXXXXXXXXXXXXX obj->register( mech => sub { WWW::Mechanize->new }); obj->get('mech'); obj('mech'); # shortcut to obj->get('mech') XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SingletonXXXXXXXXXXXXXX SingletonXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX __PACKAGE__->register( mech => sub { WWW::Mechanize->new } ); XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXX use base 'Object::Container'; XXXXXXX use Object::Container '-base'; XXXX register XXXXXXXXXXXXXXXXXXXXXXXXX "__PACKAGE__->register" XXXXX register mech => sub { WWW::Mechanize->new }; XXXXXXXXXXXXXXXXX XXXXXXXXXXX registerXXXXXXXXXXXXXXXXXXXXX get XXXXXXXXXXXXXXXXXXXXXXX Object::Container->register('WWW::Mechanize', sub { WWW::Mechanize->new }); # XXX WWW::Mechanize->new XXXXXXX my $mech = Object::Container->get('WWW::Mechanize'); # XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX Singleton XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXHTTP::Cookies XXXXXXXXXXX LWP::UserAgent XXXXXXXXXXXXXX Object::Container->register('HTTP::Cookies', sub { HTTP::Cookies->new( file => '/path/to/cookie.dat' ) }); Object::Container->register('LWP::UserAgent', sub { my $cookies = Object::Container->get('HTTP::Cookies'); LWP::UserAgent->new( cookie_jar => $cookies ); }); XXXXXXXXXXXXXXX get XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX my $ua = Object::Container->get('LWP::UserAgent'); XXXXX LWP::UserAgent X HTTP::Cookies XXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Object::Container->register({ class => 'LWP::UserAgent', preload => 1 }); initializer XXXXXXXXXXXXXXXXXX Object::Container->register({ class => 'WWW::Mechanize', initializer => sub { my $mech = WWW::Mechanize->new( stack_depth ); $mech->agent_alias('Windows IE 6'); return $mech; }, preload => 1 }); XXXXXXXXXXXXXXXXXXX Object::Container->register('WWW::Mechanize', sub { my $mech = WWW::Mechanize->new( stack_depth ); $mech->agent_alias('Windows IE 6'); return $mech; }); Object::Container->get('WWW::Mechanize'); args XXXXXXXXXXXXX: Object::Container->register({ class => 'LWP::UserAgent', args => \@args, preload => 1 }); XXXXXXXXXXXXXXXXXXXXXXX Object::Container->register('LWP::UserAgent', @args); Object::Container->get('LWP::UserAgent');
METHODS
register( $class, @args ) register( $class_or_name, $initialize_code ) Object::Container XXXXXXXXXXXXXX XXXXXXXXXXXXX Object::Container->register('WWW::Mechanize'); XXXXXXXXXXXXXXXXXXXXXXXXXX get XXXXX WWW::Mechanize->new XXXXXXXXXXXX new XXXXXXXXXXXX Object::Container->register('WWW::Mechanize', @constructor_args); XXXXXXXXXXXXXXXXXXXXXXXXXXX new XXXXXXXX new XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Object::Container->register('WWW::Mechanize', sub { my $mech = WWW::Mechanize->new( stack_depth ); $mech->agent_alias('Windows IE 6'); return $mech; }); XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Object::Container->register('ua1', sub { LWP::UserAgent->new }); Object::Container->register('ua2', sub { LWP::UserAgent->new }); XXXXXXXXXXXXXXX get($class_or_name) registerXXXXXXXXXXXXXXXXXXXXXX XXXXXXregisterXXXXXXXXXXXXXXXXXXXXXX ensure_class_loaded($class) $class XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX use XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX load_all load_all_except(@classes_or_names) XXXXXXXXXXXXXXXXXXXXgetXXXXXXXXXXXXXXXXXXXXXXXXXXXX "Copy-On-Write" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Object::Container->load_all; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Object::Container->load_all_except(qw/Foo Bar/); XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX Foo X Bar XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
EXPORT FUNCTIONS ON SUBCLASS INTERFACE
package MyContainer; use strict; use warnings; use Object::Container '-base'; XXXXXX Object::Container XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX register( $class, @args ) register( $class_or_name, $initialize_code ) register Foo => sub { my ($self) = @_; $self->ensure_class_loaded('Foo'); Foo->new; }; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "register" XXXXXXXXXXXXXXX preload(@classes_or_names) preload_all preload_all_except XXXXXXXXXXXXXXXXXXXX "load_all"X"load_all_except" XXXXXXXXXXXXXXXXXXXXX "preload_all" X "load_all" XX"preload_all_except" X "load_all_except" XXXXXXXXXXXXX
SEE ALSO
Class::Singleton, Object::Registrar.
AUTHOR
Daisuke Murase <typester@cpan.org>
COPYRIGHT & LICENSE
Copyright (c) 2009 by KAYAC Inc. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module.