1 package Plack::Session;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Plack::Util::Accessor qw( manager session options );
11 my ($class, $env, $manager ) = @_;
14 session => $env->{'psgix.session'},
15 options => $env->{'psgix.session.options'},
32 my ($self, $key) = @_;
33 $self->session->{$key};
37 my ($self, $key, $value) = @_;
38 delete $self->options->{no_store};
39 $self->session->{$key} = $value;
43 my ($self, $key) = @_;
44 delete $self->options->{no_store};
45 delete $self->session->{$key};
50 keys %{$self->session};
53 ## Lifecycle Management
57 for my $key ($self->keys) {
58 delete $self->session->{$key};
60 $self->options->{expire} = 1;
65 $self->options->{no_store} = 1;
66 $self->manager->commit($self->_data, $self->options);
77 Plack::Session - Middleware for session management
81 # Use with Middleware::Session
82 enable "Session", session_class => "Plack::Session";
86 my $session = $env->{'plack.session'}; # not psgix.
90 $session->set($key, $value);
91 $session->remove($key);
100 This is the core session object, you probably want to look
101 at L<Plack::Middleware::Session>, unless you are writing your
102 own session middleware component.
108 =item B<new ( $env, $mw )>
110 The constructor takes a PSGI request env hash reference and
111 Plack::Middleware::Session facade object.
115 This is the accessor for the session id.
119 =head2 Session Data Management
121 These methods allows you to read and write the session data like
122 Perl's normal hash. The operation is not synced to the storage until
123 you call C<finalize> on it.
127 =item B<get ( $key )>
129 =item B<set ( $key, $value )>
131 =item B<remove ( $key )>
135 =item B<session>, B<dump>
139 =head2 Session Lifecycle Management
145 This method synchronizes the session data to the data store, without
146 waiting for the response final phase.
150 This method can be called to expire the current session id.
156 All complex software has bugs lurking in it, and this module is no
157 exception. If you find a bug please either email me, or add the bug
162 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
164 =head1 COPYRIGHT AND LICENSE
166 Copyright 2009, 2010 Infinity Interactive, Inc.
168 L<http://www.iinteractive.com>
170 This library is free software; you can redistribute it and/or modify
171 it under the same terms as Perl itself.