1 package Plack::Session::Store;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use Plack::Util::Accessor qw[ _stash ];
11 my ($class, %params) = @_;
12 $params{'_stash'} ||= +{};
13 bless { %params } => $class;
17 my ($self, $session_id, $key) = @_;
18 $self->_stash->{ $session_id }->{ $key }
22 my ($self, $session_id, $key, $data) = @_;
23 $self->_stash->{ $session_id }->{ $key } = $data;
27 my ($self, $session_id, $key) = @_;
28 delete $self->_stash->{ $session_id }->{ $key };
32 my ($self, $session_id) = @_;
33 delete $self->_stash->{ $session_id }
37 my ($self, $session_id, $response) = @_;
42 my ($self, $session_id) = @_;
43 $self->_stash->{ $session_id } || {};
54 Plack::Session::Store - Basic in-memory session store
59 use Plack::Middleware::Session;
60 use Plack::Session::Store;
63 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
67 enable 'Session'; # this is the defalt store
73 This is a very basic in-memory session data store. It is volatile
74 storage and not recommended for multiprocessing environments. However
75 it is very useful for development and testing.
77 This should be considered the store "base" class (although
78 subclassing is not a requirement) and defines the spec for
79 all B<Plack::Session::Store::*> modules. You will only
80 need to override a couple methods if you do subclass. See
81 the other B<Plack::Session::Store::*> for examples of this.
87 =item B<new ( %params )>
89 No parameters are expected to this constructor.
93 =head2 Session Data Management
95 These methods fetch data from the session storage. It can only fetch,
96 store or delete a single key at a time.
100 =item B<fetch ( $session_id, $key )>
102 =item B<store ( $session_id, $key, $data )>
104 =item B<delete ( $session_id, $key )>
108 =head2 Storage Management
112 =item B<persist ( $session_id, $response )>
114 This method will perform any data persistence nessecary to maintain
115 data across requests. This method is called by the L<Plack::Session>
116 C<finalize> method. The C<$response> is expected to be a L<Plack::Response>
117 instance or an object with an equivalent interface.
119 =item B<cleanup ( $session_id )>
121 This method is called by the L<Plack::Session> C<expire> method and
122 is used to remove any session data.
124 =item B<dump_session ( $session_id )>
126 This method is mostly for debugging purposes, it will always return
127 a HASH ref, even if no data is actually being stored (in which case
128 the HASH ref will be empty).
134 All complex software has bugs lurking in it, and this module is no
135 exception. If you find a bug please either email me, or add the bug
140 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
142 =head1 COPYRIGHT AND LICENSE
144 Copyright 2009 Infinity Interactive, Inc.
146 L<http://www.iinteractive.com>
148 This library is free software; you can redistribute it and/or modify
149 it under the same terms as Perl itself.