Scope::Session::Flyweight - Attach light-weight instance creation for Scope::Session
Version 0.01
work as factory
use Scope::Session::Flyweight; my $flyweight = Scope::Session::Flyweight->acquire( q|Test::Object| => ( id => 10 ) ); my $flyweight2 = Scope::Session::Flyweight->acquire( q|Test::Object| => ( id => 10 ) );
work as role
package Test::Object; use Scope::Session::Flyweight acquire => 1; sub identifier { my ( $class, %args ) = @_; return $args{id}; } sub new { my ( $class, %args ) = @_; return bless {%args} => $class; } my $flyweight = Test::Object->acquire( id => 10 ); my $flyweight2 = Test::Object->acquire( id => 10 );
target class must be implemented following methods.
get constructor options and return object identity string.
create instance
get a same identifier instance
Daichi Hiroki, <hirokidaichi<AT>gmail.com>
<hirokidaichi<AT>gmail.com>
Copyright 2009 Daichi Hiroki.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Scope::Session, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scope::Session
CPAN shell
perl -MCPAN -e shell install Scope::Session
For more information on module installation, please visit the detailed CPAN module installation guide.