1 package Plack::Session;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Plack::Util::Accessor qw( manager _data options );
11 my ($class, %params) = @_;
12 bless { %params } => $class;
28 my ($self, $key) = @_;
33 my ($self, $key, $value) = @_;
34 delete $self->options->{no_commit};
35 $self->_data->{$key} = $value;
39 my ($self, $key) = @_;
40 delete $self->options->{no_commit};
41 delete $self->_data->{$key};
49 ## Lifecycle Management
53 for my $key ($self->keys) {
54 delete $self->_data->{$key};
56 $self->options->{expire} = 1;
61 $self->options->{no_commit} = 1;
62 $self->manager->commit($self->_data, $self->options);
73 Plack::Session - Middleware for session management
77 # Use with Middleware::Session
78 enable "Session", session_class => "Plack::Session";
87 This is the core session object, you probably want to look
88 at L<Plack::Middleware::Session>, unless you are writing your
89 own session middleware component.
95 =item B<new ( %params )>
97 The constructor expects keys in C<%params> for I<state>,
98 I<store> and I<request>. The I<request> param is expected to be
99 a L<Plack::Request> instance or an object with an equivalent
104 This is the accessor for the session id.
108 This is expected to be a L<Plack::Session::State> instance or
109 an object with an equivalent interface.
113 This is expected to be a L<Plack::Session::Store> instance or
114 an object with an equivalent interface.
118 =head2 Session Data Management
120 These methods allows you to read and write the session data like
121 Perl's normal hash. The operation is not synced to the storage until
122 you call C<finalize> on it.
126 =item B<get ( $key )>
128 =item B<set ( $key, $value )>
130 =item B<remove ( $key )>
136 =head2 Session Lifecycle Management
142 This method synchronizes the session data to the data store, without
143 waiting for the response final phase.
147 This method can be called to expire the current session id. It marks
148 the session as expire and call the C<cleanup> method on the C<store>
149 and the C<expire_session_id> method on the C<state>.
151 =item B<finalize ( $manager, $response )>
153 This method should be called at the end of the response cycle. It will
154 call the C<store> method on the C<store> and the C<expire_session_id>
155 method on the C<state>. The C<$response> is expected to be a
156 L<Plack::Response> instance or an object with an equivalent interface.
162 All complex software has bugs lurking in it, and this module is no
163 exception. If you find a bug please either email me, or add the bug
168 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
170 =head1 COPYRIGHT AND LICENSE
172 Copyright 2009, 2010 Infinity Interactive, Inc.
174 L<http://www.iinteractive.com>
176 This library is free software; you can redistribute it and/or modify
177 it under the same terms as Perl itself.