From: Stevan Little Date: Sun, 13 Dec 2009 18:27:00 +0000 (-0500) Subject: adding in the dump_session method to the Store classes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Session.git;a=commitdiff_plain;h=74e0eff08e280c17df453273d05acc3065365de3 adding in the dump_session method to the Store classes --- diff --git a/lib/Plack/Session/Store.pm b/lib/Plack/Session/Store.pm index 572730b..32ee737 100644 --- a/lib/Plack/Session/Store.pm +++ b/lib/Plack/Session/Store.pm @@ -35,6 +35,11 @@ sub persist { () } +sub dump_session { + my ($self, $session_id) = @_; + $self->_stash->{ $session_id } || {}; +} + 1; __END__ @@ -113,6 +118,12 @@ instance or an object with an equivalent interface. 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 diff --git a/lib/Plack/Session/Store/Cache.pm b/lib/Plack/Session/Store/Cache.pm index 7b44b00..62232f8 100644 --- a/lib/Plack/Session/Store/Cache.pm +++ b/lib/Plack/Session/Store/Cache.pm @@ -53,6 +53,11 @@ sub cleanup { $self->cache->remove($session_id); } +sub dump_session { + my ($self, $session_id) = @_; + $self->cache->get( $session_id ) || {}; +} + 1; __END__ diff --git a/lib/Plack/Session/Store/File.pm b/lib/Plack/Session/Store/File.pm index 8da664c..0e5918d 100644 --- a/lib/Plack/Session/Store/File.pm +++ b/lib/Plack/Session/Store/File.pm @@ -71,6 +71,13 @@ sub _deserialize { $self->deserializer->( $file_path ); } +sub dump_session { + my ($self, $session_id) = @_; + my $file_path = $self->_get_session_file_path( $session_id ); + return {} unless -f $file_path; + $self->deserializer->( $file_path ); +} + 1; diff --git a/lib/Plack/Session/Store/Null.pm b/lib/Plack/Session/Store/Null.pm index 139a44b..dceca1e 100644 --- a/lib/Plack/Session/Store/Null.pm +++ b/lib/Plack/Session/Store/Null.pm @@ -9,6 +9,8 @@ sub delete {} sub cleanup {} sub persist {} +sub dump_session { +{} } + 1; __END__ diff --git a/t/lib/TestSession.pm b/t/lib/TestSession.pm index 3f6371b..579689f 100644 --- a/t/lib/TestSession.pm +++ b/t/lib/TestSession.pm @@ -44,12 +44,22 @@ sub run_all_tests { is($s->get('foo'), 'bar', '... got the foo value back successfully from session'); + ok(!$s->get('bar'), '... no value stored in foo for session'); + + lives_ok { + $s->set( bar => 'baz' ); + } '... set the value successfully in session'; + + is($s->get('bar'), 'baz', '... got the foo value back successfully from session'); + my $resp = $r->new_response; lives_ok { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[0] ), { foo => 'bar', bar => 'baz' }, '... got the session dump we expected'); + $response_test->( $resp, $sids[0] ); } @@ -79,6 +89,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected'); + $response_test->( $resp, $sids[1] ); } @@ -107,6 +119,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[0] ), { bar => 'baz' }, '... got the session dump we expected'); + $response_test->( $resp, $sids[0] ); } @@ -130,6 +144,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected'); + $response_test->( $resp, $sids[1] ); } @@ -147,7 +163,7 @@ sub run_all_tests { ok(!$s->get('foo'), '... no value stored for foo in session'); lives_ok { - $s->set( bar => 'baz' ); + $s->set( baz => 'gorch' ); } '... set the bar value successfully in session'; my $resp = $r->new_response; @@ -156,6 +172,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[0] ), { bar => 'baz', baz => 'gorch' }, '... got the session dump we expected'); + $response_test->( $resp, $sids[0] ); } @@ -180,6 +198,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[0] ), {}, '... got the session dump we expected'); + $response_test->( $resp, $sids[0], 1 ); } @@ -203,6 +223,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[2] ), {}, '... got the session dump we expected'); + $response_test->( $resp, $sids[2] ); } @@ -225,6 +247,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected'); + $response_test->( $resp, $sids[1] ); } @@ -255,6 +279,8 @@ sub run_all_tests { $s->finalize( $resp ); } '... finalized session successfully'; + is_deeply( $s->store->dump_session( $s->id ), { foo => 'baz' }, '... got the session dump we expected'); + $response_test->( $resp, $s ); } }