Object::Stock - An object factory
# singleton object of LWP::UserAgent
use Object::Stock;
my $stock = Object::Stock->new(
builder => sub { LWP::UserAgent->new( @_ ) },
);
my $obj_x = $stock->get( agent => 'MyAgent/1.0' );
my $obj_y = $stock->get( agent => 'KoolAgent/0.3' );
print $obj_x->agent."\n"; # MyAgent/1.0
print $obj_y->agent."\n"; # KoolAgent/0.3
$stock->is_stored( agent => 'MyAgent/1.0' ); # TRUE
$stock->is_stored( agent => 'KoolAgent/0.3' ); # FALSE
# some objects(LWP::UserAgent) in Object::Stock
use Object::Stock;
my $stock = Object::Stock->new(
builder => sub { LWP::UserAgent->new( @_ ) },
max_objects => 10,
);
my $obj_x = $stock->get( agent => 'MyAgent/1.0' );
my $obj_y = $stock->get( agent => 'KoolAgent/0.3' );
print $obj_x->agent."\n"; # MyAgent/1.0
print $obj_y->agent."\n"; # KoolAgent/0.3
$stock->is_stored( agent => 'MyAgent/1.0' ); # TRUE
$stock->is_stored( agent => 'KoolAgent/0.3' ); # TRUE!!!
Object::Stock is An object factory class.
Object::Stock identifies objects by their instantiation attributes.
satoshi azuma ytnobody@gmail.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.