1 package Plack::Middleware::Session;
11 use parent 'Plack::Middleware';
13 use Plack::Util::Accessor qw(
22 $self->session_class( 'Plack::Session' ) unless $self->session_class;
23 $self->state( 'Cookie' ) unless $self->state;
25 $self->state( $self->inflate_backend('Plack::Session::State', $self->state) );
26 $self->store( $self->inflate_backend('Plack::Session::Store', $self->store) );
30 my($self, $prefix, $backend) = @_;
32 return $backend if defined $backend && Scalar::Util::blessed $backend;
35 push @class, $backend if defined $backend; # undef means the root class
38 Plack::Util::load_class(@class)->new();
45 $env->{'plack.session'} = $self->session_class->new(
46 state => $self->state,
47 store => $self->store,
48 request => Plack::Request->new( $env )
51 my $res = $self->app->($env);
52 $self->response_cb($res, sub {
53 my $res = Plack::Response->new(@{$_[0]});
54 $env->{'plack.session'}->finalize( $res );
55 @{$_[0]} = @{$res->finalize};
67 Plack::Middleware::Session - Middleware for session management
74 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
82 # Or, use the File store backend (great if you use multiprocess server)
83 # For more options, see perldoc Plack::Session::Store::File
85 enable 'Session', store => 'File';
91 This is a Plack Middleware component for session management. By
92 default it will use cookies to keep session state and store data in
93 memory. This distribution also comes with other state and store
94 solutions. See perldoc for these backends how to use them.
100 =item L<Plack::Session::State>
102 This will maintain session state by passing the session through
103 the request params. It does not do this automatically though,
104 you are responsible for passing the session param.
106 =item L<Plack::Session::State::Cookie>
108 This will maintain session state using browser cookies.
116 =item L<Plack::Session::Store>
118 This is your basic in-memory session data store. It is volatile storage
119 and not recommended for multiprocessing environments. However it is
120 very useful for development and testing.
122 =item L<Plack::Session::Store::File>
124 This will persist session data in a file. By default it uses
125 L<Storable> but it can be configured to have a custom serializer and
128 =item L<Plack::Session::Store::Cache>
130 This will persist session data using the L<Cache> interface.
132 =item L<Plack::Session::Store::Null>
134 Sometimes you don't care about storing session data, in that case
135 you can use this noop module.
141 All complex software has bugs lurking in it, and this module is no
142 exception. If you find a bug please either email me, or add the bug
149 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
151 =head1 COPYRIGHT AND LICENSE
153 Copyright 2009 Infinity Interactive, Inc.
155 L<http://www.iinteractive.com>
157 This library is free software; you can redistribute it and/or modify
158 it under the same terms as Perl itself.