Plack::Session::State - Basic parameter-based session state
use Plack::Builder; use Plack::Middleware::Session; use Plack::Session::State; my $app = sub { return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ]; }; builder { enable 'Session', state => Plack::Session::State->new; $app; };
This will maintain session state by passing the session through the request params. It does not do this automatically though, you are responsible for passing the session param.
This should be considered the state "base" class (although subclassing is not a requirement) and defines the spec for all Plack::Session::State::* modules. You will only need to override a couple methods if you do subclass. See Plack::Session::State::Cookie for an example of this.
The %params can include session_key, sid_generator and sid_checker however in both cases a default will be provided for you.
%params
This is the name of the session key, it default to 'plack_session'.
This is a CODE ref used to generate unique session ids, by default it will generate a SHA1 using fairly sufficient entropy. If you are concerned or interested, just read the source.
This is a regex used to validate requested session id.
Given a $request this will first attempt to extract the session, if the is expired or does not exist, it will then generate a new session. The $request is expected to be a Plack::Request instance or an object with an equivalent interface.
$request
This is the method used to extract the session id from a $request. Subclasses will often only need to override this method and the finalize method.
finalize
This will use the sid_validator regex and confirm that the $session_id is valid.
sid_validator
$session_id
This will attempt to extract the session from a $request by looking for the session_key in the $request params. It will then check to see if the session is valid and that it has not expired. It will return the session id if everything is good or undef otherwise. The $request is expected to be a Plack::Request instance or an object with an equivalent interface.
session_key
This will generate a new session id using the sid_generator callback. The $request argument is not used by this method but is there for use by subclasses. The $request is expected to be a Plack::Request instance or an object with an equivalent interface.
sid_generator
Given a $session_id and a $response this will perform any finalization nessecary to preserve state. This method is called by the Plack::Session finalize method. The $response is expected to be a Plack::Response instance or an object with an equivalent interface.
$response
This will mark the session for $id as expired. This method is called by the Plack::Session expire method.
$id
expire
This will check to see if the session $id has been marked as expired.
Given an session $id this will return undef if the session is expired or return the $id if it is not.
undef
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Stevan Little <stevan.little@iinteractive.com>
Copyright 2009 Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Plack::Middleware::Session, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Session
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Session
For more information on module installation, please visit the detailed CPAN module installation guide.