1 package Plack::Middleware::Session;
8 use Plack::Session::State::Cookie;
9 use Plack::Session::Store;
11 use parent 'Plack::Middleware';
13 use Plack::Util::Accessor qw( state store );
17 unless ($self->state) {
18 $self->state( Plack::Session::State::Cookie->new );
21 unless ($self->store) {
22 $self->store( Plack::Session::Store->new );
30 $env->{'plack.session'} = Plack::Session->new(
31 state => $self->state,
32 store => $self->store,
33 request => Plack::Request->new( $env )
36 my $res = $self->app->($env);
37 $self->response_cb($res, sub {
38 my $res = Plack::Response->new(@{$_[0]});
39 $env->{'plack.session'}->finalize( $res );
40 @{$_[0]} = @{$res->finalize};
52 Plack::Middleware::Session - Middleware for session management
57 use Plack::Middleware::Session;
60 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
70 This is a Plack Middleware component for session management. By
71 default it will use cookies to keep session state and store data
72 in memory. This distribution comes also comes with other state
79 =item L<Plack::Session::State>
81 This will maintain session state by passing the session through
82 the request params. It does not do this automatically though,
83 you are responsible for passing the session param.
85 =item L<Plack::Session::State::Cookie>
87 This will maintain session state using browser cookies.
95 =item L<Plack::Session::Store>
97 This is your basic in-memory session data store. It is volatile storage
98 and not recommended for multiprocessing environments. However it is
99 very useful for development and testing.
101 =item L<Plack::Session::Store::File>
103 This will persist session data in a file. By default it uses
104 L<Storable> but it can be configured to have a custom serializer and
107 =item L<Plack::Session::Store::CHI>
109 This will persist session data using the L<CHI> module. This
110 offers a lot of flexibility due to the many excellent L<CHI>
113 =item L<Plack::Session::Store::Null>
115 Sometimes you don't care about storing session data, in that case
116 you can use this noop module.
122 All complex software has bugs lurking in it, and this module is no
123 exception. If you find a bug please either email me, or add the bug
130 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
132 =head1 COPYRIGHT AND LICENSE
134 Copyright 2009 Infinity Interactive, Inc.
136 L<http://www.iinteractive.com>
138 This library is free software; you can redistribute it and/or modify
139 it under the same terms as Perl itself.