Scope::Container - scope based container
use Scope::Container; sub getdb { if ( my $dbh = scope_container('db') ) { return $dbh; } else { my $dbh = DBI->connect(...); scope_container('db', $dbh) return $dbh; } } for (1..3) { my $contaier = start_scope_container(); getdb(); # do connect getdb(); # from container getdb(); # from container # $container scope out and disconnect from db } getdb(); # do connect
Scope::Container is scope based container for temporary items and Database Connections.
Initializing container. The default behavior is inherited all the previous container's data. If set -clear arguments, save previous container's data and create new data.
return values is Scope::Container object. if this object scope exits, current container will be removed, return to the previous state.
getter, setter of container data.
Check if context is initialized
There is a limit to the order in which the Scope::Container object is deleted. If race condition found, remove all data.
my $sc = start_scope_container(); scope_container('bar', 'foo'); my $sc2 = start_scope_container(); scope_container('bar', 'baz'); undef $sc; scope_container('bar'); #null
Masahiro Nagano <kazeburo {at} gmail.com>
Fuji, Goro (gfx)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Scope::Container, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scope::Container
CPAN shell
perl -MCPAN -e shell install Scope::Container
For more information on module installation, please visit the detailed CPAN module installation guide.