1 package Plack::Session;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Plack::Util::Accessor qw( session options );
11 my ($class, $env) = @_;
13 session => $env->{'psgix.session'},
14 options => $env->{'psgix.session.options'},
31 my ($self, $key) = @_;
32 $self->session->{$key};
36 my ($self, $key, $value) = @_;
37 delete $self->options->{no_store};
38 $self->session->{$key} = $value;
42 my ($self, $key) = @_;
43 delete $self->options->{no_store};
44 delete $self->session->{$key};
49 keys %{$self->session};
52 ## Lifecycle Management
56 for my $key ($self->keys) {
57 delete $self->session->{$key};
59 $self->options->{expire} = 1;
70 Plack::Session - Middleware for session management
74 # Use with Middleware::Session
75 enable "Session", session_class => "Plack::Session";
79 my $session = $env->{'plack.session'}; # not psgix.
83 $session->set($key, $value);
84 $session->remove($key);
92 This is the core session object, you probably want to look
93 at L<Plack::Middleware::Session>, unless you are writing your
94 own session middleware component.
100 =item B<new ( $env )>
102 The constructor takes a PSGI request env hash reference.
106 This is the accessor for the session id.
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 )>
126 =item B<session>, B<dump>
130 =head2 Session Lifecycle Management
136 This method can be called to expire the current session id.
142 All complex software has bugs lurking in it, and this module is no
143 exception. If you find a bug please either email me, or add the bug
148 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
150 =head1 COPYRIGHT AND LICENSE
152 Copyright 2009, 2010 Infinity Interactive, Inc.
154 L<http://www.iinteractive.com>
156 This library is free software; you can redistribute it and/or modify
157 it under the same terms as Perl itself.