1 package Plack::Session;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Plack::Util::Accessor qw[
15 my ($class, %params) = @_;
16 my $request = delete $params{'request'};
17 $params{'id'} = $params{'state'}->get_session_id( $request );
18 bless { %params } => $class;
24 my ($self, $key) = @_;
25 $self->store->fetch( $self->id, $key )
29 my ($self, $key, $value) = @_;
30 $self->store->store( $self->id, $key, $value );
34 my ($self, $key) = @_;
35 $self->store->delete( $self->id, $key );
38 ## Lifecycle Management
42 $self->store->cleanup( $self->id );
43 $self->state->expire_session_id( $self->id );
47 my ($self, $response) = @_;
48 $self->store->persist( $self->id, $response );
49 $self->state->finalize( $self->id, $response );
60 Plack::Session - Middleware for session management
66 my $store = Plack::Session::Store->new;
67 my $state = Plack::Session::State->new;
69 my $s = Plack::Session->new(
72 request => Plack::Request->new( $env )
79 This is the core session object, you probably want to look
80 at L<Plack::Middleware::Session>, unless you are writing your
81 own session middleware component.
87 =item B<new ( %params )>
89 The constructor expects keys in C<%params> for I<state>,
90 I<store> and I<request>. The I<request> param is expected to be
91 a L<Plack::Request> instance or an object with an equivalent
96 This is the accessor for the session id.
100 This is expected to be a L<Plack::Session::State> instance or
101 an object with an equivalent interface.
105 This is expected to be a L<Plack::Session::Store> instance or
106 an object with an equivalent interface.
110 =head2 Session Data Storage
112 These methods delegate to appropriate methods on the C<store>
113 to manage your session data.
117 =item B<get ( $key )>
119 =item B<set ( $key, $value )>
121 =item B<remove ( $key )>
125 =head2 Session Lifecycle Management
131 This method can be called to expire the current session id. It
132 will call the C<cleanup> method on the C<store> and the C<finalize>
133 method on the C<state>, passing both of them the session id and
136 =item B<finalize ( $response )>
138 This method should be called at the end of the response cycle. It
139 will call the C<persist> method on the C<store> and the
140 C<expire_session_id> method on the C<state>, passing both of them
141 the session id. The C<$response> is expected to be a L<Plack::Response>
142 instance or an object with an equivalent interface.
148 All complex software has bugs lurking in it, and this module is no
149 exception. If you find a bug please either email me, or add the bug
154 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
156 =head1 COPYRIGHT AND LICENSE
158 Copyright 2009, 2010 Infinity Interactive, Inc.
160 L<http://www.iinteractive.com>
162 This library is free software; you can redistribute it and/or modify
163 it under the same terms as Perl itself.