Plack::Middleware::Scope::Container - per-request container
use Plack::Builder; builder { enable "Plack::Middleware::Scope::Container"; $app }; # in your application package MyApp; use Scope::Container; sub getdb { if ( my $dbh = scope_container('db') ) { return $dbh; } else { my $dbh = DBI->connect(...); scope_container('db', $dbh) return $dbh; } } sub app { my $env = shift; getdb(); # do connect getdb(); # from container getdb(); # from container return [ '200', [] ["OK"]]; # disconnect from db at end of request }
Plack::Middleware::Scope::Container and Scope::Container work like mod_perl's pnotes. It gives a per-request container to your application.
Masahiro Nagano <kazeburo {at} gmail.com>
Scope::Container, Plack::Middleware::Scope::Session
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Plack::Middleware::Scope::Container, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Scope::Container
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Scope::Container
For more information on module installation, please visit the detailed CPAN module installation guide.