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;
23 my ($self, $key) = @_;
28 my ($self, $key, $value) = @_;
29 delete $self->options->{no_commit};
30 $self->_data->{$key} = $value;
34 my ($self, $key) = @_;
35 delete $self->options->{no_commit};
36 delete $self->_data->{$key};
44 ## Lifecycle Management
48 $self->options->{expire} = 1;
53 $self->options->{no_commit} = 1;
54 $self->manager->commit($self->_data, $self->options);
65 Plack::Session - Middleware for session management
69 # Use with Middleware::Session
70 enable "Session", session_class => "Plack::Session";
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 Management
112 These methods allows you to read and write the session data like
113 Perl's normal hash. The operation is not synced to the storage until
114 you call C<finalize> on it.
118 =item B<get ( $key )>
120 =item B<set ( $key, $value )>
122 =item B<remove ( $key )>
128 =head2 Session Lifecycle Management
134 This method synchronizes the session data to the data store, without
135 waiting for the response final phase.
139 This method can be called to expire the current session id. It marks
140 the session as expire and call the C<cleanup> method on the C<store>
141 and the C<expire_session_id> method on the C<state>.
143 =item B<finalize ( $manager, $response )>
145 This method should be called at the end of the response cycle. It will
146 call the C<store> method on the C<store> and the C<expire_session_id>
147 method on the C<state>. The C<$response> is expected to be a
148 L<Plack::Response> instance or an object with an equivalent interface.
154 All complex software has bugs lurking in it, and this module is no
155 exception. If you find a bug please either email me, or add the bug
160 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
162 =head1 COPYRIGHT AND LICENSE
164 Copyright 2009, 2010 Infinity Interactive, Inc.
166 L<http://www.iinteractive.com>
168 This library is free software; you can redistribute it and/or modify
169 it under the same terms as Perl itself.