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
69 =item B<new ( %params )>
71 The constructor expects keys in C<%params> for I<state>,
72 I<store> and I<request>. The I<request> param is expected to be
73 a L<Plack::Request> instance or an object with an equivalent
78 This is the accessor for the session id.
82 This is expected to be a L<Plack::Session::State> instance or
83 an object with an equivalent interface.
87 This is expected to be a L<Plack::Session::Store> instance or
88 an object with an equivalent interface.
92 =head2 Session Data Storage
94 These methods delegate to appropriate methods on the C<store>.
100 =item B<set ( $key, $value )>
102 =item B<remove ( $key )>
106 =head2 Session Lifecycle Management
112 This method can be called to expire the current session id. It
113 will call the C<cleanup> method on the C<store> and the C<finalize>
114 method on the C<state>, passing both of them the session id and
117 =item B<finalize ( $response )>
119 This method should be called at the end of the response cycle. It
120 will call the C<persist> method on the C<store> and the
121 C<expire_session_id> method on the C<state>, passing both of them
122 the session id. The C<$response> is expected to be a L<Plack::Response>
123 instance or an object with an equivalent interface.
129 All complex software has bugs lurking in it, and this module is no
130 exception. If you find a bug please either email me, or add the bug
135 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
137 =head1 COPYRIGHT AND LICENSE
139 Copyright 2009 Infinity Interactive, Inc.
141 L<http://www.iinteractive.com>
143 This library is free software; you can redistribute it and/or modify
144 it under the same terms as Perl itself.