1 package Plack::Middleware::Session;
11 use parent 'Plack::Middleware';
13 use Plack::Util::Accessor qw( state store );
18 $self->state('Cookie') unless $self->state;
20 $self->state( $self->inflate_backend('Plack::Session::State', $self->state) );
21 $self->store( $self->inflate_backend('Plack::Session::Store', $self->store) );
25 my($self, $prefix, $backend) = @_;
27 return $backend if defined $backend && Scalar::Util::blessed $backend;
30 push @class, $backend if defined $backend; # undef means the root class
33 Plack::Util::load_class(@class)->new();
40 $env->{'plack.session'} = Plack::Session->new(
41 state => $self->state,
42 store => $self->store,
43 request => Plack::Request->new( $env )
46 my $res = $self->app->($env);
47 $self->response_cb($res, sub {
48 my $res = Plack::Response->new(@{$_[0]});
49 $env->{'plack.session'}->finalize( $res );
50 @{$_[0]} = @{$res->finalize};
62 Plack::Middleware::Session - Middleware for session management
69 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
77 # Or, use the File store backend (great if you use multiprocess server)
78 # For more options, see perldoc Plack::Session::Store::File
80 enable 'Session', store => 'File';
86 This is a Plack Middleware component for session management. By
87 default it will use cookies to keep session state and store data in
88 memory. This distribution also comes with other state and store
89 solutions. See perldoc for these backends how to use them.
95 =item L<Plack::Session::State>
97 This will maintain session state by passing the session through
98 the request params. It does not do this automatically though,
99 you are responsible for passing the session param.
101 =item L<Plack::Session::State::Cookie>
103 This will maintain session state using browser cookies.
111 =item L<Plack::Session::Store>
113 This is your basic in-memory session data store. It is volatile storage
114 and not recommended for multiprocessing environments. However it is
115 very useful for development and testing.
117 =item L<Plack::Session::Store::File>
119 This will persist session data in a file. By default it uses
120 L<Storable> but it can be configured to have a custom serializer and
123 =item L<Plack::Session::Store::CHI>
125 This will persist session data using the L<CHI> module. This
126 offers a lot of flexibility due to the many excellent L<CHI>
129 =item L<Plack::Session::Store::Null>
131 Sometimes you don't care about storing session data, in that case
132 you can use this noop module.
138 All complex software has bugs lurking in it, and this module is no
139 exception. If you find a bug please either email me, or add the bug
146 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
148 =head1 COPYRIGHT AND LICENSE
150 Copyright 2009 Infinity Interactive, Inc.
152 L<http://www.iinteractive.com>
154 This library is free software; you can redistribute it and/or modify
155 it under the same terms as Perl itself.