1 package Plack::Session;
5 use Plack::Util::Accessor qw[
12 my ($class, %params) = @_;
13 my $request = delete $params{'request'};
14 $params{'id'} = $params{'state'}->get_session_id( $request );
15 bless { %params } => $class;
21 my ($self, $key) = @_;
22 $self->store->fetch( $self->id, $key )
26 my ($self, $key, $value) = @_;
27 $self->store->store( $self->id, $key, $value );
31 my ($self, $key) = @_;
32 $self->store->delete( $self->id, $key );
35 ## Lifecycle Management
39 $self->store->cleanup( $self->id );
40 $self->state->expire_session_id( $self->id );
44 my ($self, $response) = @_;
45 $self->store->persist( $self->id, $response );
46 $self->state->finalize( $self->id, $response );
57 Plack::Session - Middleware for session management
63 my $store = Plack::Session::Store->new;
64 my $state = Plack::Session::State->new;
66 my $s = Plack::Session->new(
69 request => Plack::Request->new( $env )
76 This is the core session object, you probably want to look
77 at L<Plack::Middlware::Session>, unless you are writing your
78 own session middleware component.
84 =item B<new ( %params )>
86 The constructor expects keys in C<%params> for I<state>,
87 I<store> and I<request>. The I<request> param is expected to be
88 a L<Plack::Request> instance or an object with an equivalent
93 This is the accessor for the session id.
97 This is expected to be a L<Plack::Session::State> instance or
98 an object with an equivalent interface.
102 This is expected to be a L<Plack::Session::Store> instance or
103 an object with an equivalent interface.
107 =head2 Session Data Storage
109 These methods delegate to appropriate methods on the C<store>
110 to manage your session data.
114 =item B<get ( $key )>
116 =item B<set ( $key, $value )>
118 =item B<remove ( $key )>
122 =head2 Session Lifecycle Management
128 This method can be called to expire the current session id. It
129 will call the C<cleanup> method on the C<store> and the C<finalize>
130 method on the C<state>, passing both of them the session id and
133 =item B<finalize ( $response )>
135 This method should be called at the end of the response cycle. It
136 will call the C<persist> method on the C<store> and the
137 C<expire_session_id> method on the C<state>, passing both of them
138 the session id. The C<$response> is expected to be a L<Plack::Response>
139 instance or an object with an equivalent interface.
145 All complex software has bugs lurking in it, and this module is no
146 exception. If you find a bug please either email me, or add the bug
151 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
153 =head1 COPYRIGHT AND LICENSE
155 Copyright 2009 Infinity Interactive, Inc.
157 L<http://www.iinteractive.com>
159 This library is free software; you can redistribute it and/or modify
160 it under the same terms as Perl itself.