X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FPlack%2FSession%2FStore.pm;h=0f87ce6c4c2ee7e3b1a00ffaac611a07e0ceda39;hb=9dcca820988aab7409efc79baf34bb5d8f05bc63;hp=3f52679fc4fd32eab267396b12c04c9b1db5e5cf;hpb=06190e8b6e64fd1c33fc2089ddf0d42e0db28f4b;p=catagits%2FWeb-Session.git diff --git a/lib/Plack/Session/Store.pm b/lib/Plack/Session/Store.pm index 3f52679..0f87ce6 100644 --- a/lib/Plack/Session/Store.pm +++ b/lib/Plack/Session/Store.pm @@ -2,9 +2,16 @@ package Plack::Session::Store; use strict; use warnings; +our $VERSION = '0.02'; +our $AUTHORITY = 'cpan:STEVAN'; + use Plack::Util::Accessor qw[ _stash ]; -sub new { bless { _stash => {} } => shift } +sub new { + my ($class, %params) = @_; + $params{'_stash'} ||= +{}; + bless { %params } => $class; +} sub fetch { my ($self, $session_id, $key) = @_; @@ -21,14 +28,125 @@ sub delete { delete $self->_stash->{ $session_id }->{ $key }; } -sub persist { +sub cleanup { my ($self, $session_id) = @_; + delete $self->_stash->{ $session_id } +} + +sub persist { + my ($self, $session_id, $response) = @_; () } -sub cleanup { +sub dump_session { my ($self, $session_id) = @_; - delete $self->_stash->{ $session_id } + $self->_stash->{ $session_id } || {}; } -1; \ No newline at end of file +1; + +__END__ + +=pod + +=head1 NAME + +Plack::Session::Store - Basic in-memory session store + +=head1 SYNOPSIS + + use Plack::Builder; + use Plack::Middleware::Session; + use Plack::Session::Store; + + my $app = sub { + return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ]; + }; + + builder { + enable 'Session'; # this is the defalt store + $app; + }; + +=head1 DESCRIPTION + +This is a very basic in-memory session data store. It is volatile +storage and not recommended for multiprocessing environments. However +it is very useful for development and testing. + +This should be considered the store "base" class (although +subclassing is not a requirement) and defines the spec for +all B modules. You will only +need to override a couple methods if you do subclass. See +the other B for examples of this. + +=head1 METHODS + +=over 4 + +=item B + +No parameters are expected to this constructor. + +=back + +=head2 Session Data Management + +These methods fetch data from the session storage. It can only fetch, +store or delete a single key at a time. + +=over 4 + +=item B + +=item B + +=item B + +=back + +=head2 Storage Management + +=over 4 + +=item B + +This method will perform any data persistence nessecary to maintain +data across requests. This method is called by the L +C method. The C<$response> is expected to be a L +instance or an object with an equivalent interface. + +=item B + +This method is called by the L C method and +is used to remove any session data. + +=item B + +This method is mostly for debugging purposes, it will always return +a HASH ref, even if no data is actually being stored (in which case +the HASH ref will be empty). + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2009 Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut +