adding in the dump_session method to the Store classes
Stevan Little [Sun, 13 Dec 2009 18:27:00 +0000 (13:27 -0500)]
lib/Plack/Session/Store.pm
lib/Plack/Session/Store/Cache.pm
lib/Plack/Session/Store/File.pm
lib/Plack/Session/Store/Null.pm
t/lib/TestSession.pm

index 572730b..32ee737 100644 (file)
@@ -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<Plack::Session> C<expire> method and
 is used to remove any session data.
 
+=item B<dump_session ( $session_id )>
+
+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
index 7b44b00..62232f8 100644 (file)
@@ -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__
index 8da664c..0e5918d 100644 (file)
@@ -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;
 
index 139a44b..dceca1e 100644 (file)
@@ -9,6 +9,8 @@ sub delete  {}
 sub cleanup {}
 sub persist {}
 
+sub dump_session { +{} }
+
 1;
 
 __END__
index 3f6371b..579689f 100644 (file)
@@ -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 );
     }
 }