[Catalyst-commits] r8852 - in branches/Catalyst-Plugin-Session: . both both/lib/Catalyst/Plugin both/t

ssalvi at dev.catalyst.perl.org ssalvi at dev.catalyst.perl.org
Fri Dec 12 21:23:46 GMT 2008


Author: ssalvi
Date: 2008-12-12 21:23:46 +0000 (Fri, 12 Dec 2008)
New Revision: 8852

Added:
   branches/Catalyst-Plugin-Session/both/
Modified:
   branches/Catalyst-Plugin-Session/
   branches/Catalyst-Plugin-Session/both/Changes
   branches/Catalyst-Plugin-Session/both/lib/Catalyst/Plugin/Session.pm
   branches/Catalyst-Plugin-Session/both/t/03_flash.t
Log:
 r8858 at minifig:  sergio | 2008-12-12 15:56:33 -0500
 applying both patches (finalize_race_condition and flash_in_session)
 r8859 at minifig:  sergio | 2008-12-12 16:09:24 -0500
 updating changelog



Property changes on: branches/Catalyst-Plugin-Session
___________________________________________________________________
Name: svk:merge
   - dd4bbdde-bd5d-0410-bf86-8d378e22a0ef:/local/Catalyst/branches/Catalyst-Plugin-Session:8826
   + dd4bbdde-bd5d-0410-bf86-8d378e22a0ef:/local/Catalyst/branches/Catalyst-Plugin-Session:8859

Copied: branches/Catalyst-Plugin-Session/both (from rev 8829, branches/Catalyst-Plugin-Session/finalize_race_condition)

Modified: branches/Catalyst-Plugin-Session/both/Changes
===================================================================
--- branches/Catalyst-Plugin-Session/finalize_race_condition/Changes	2008-12-11 16:42:39 UTC (rev 8829)
+++ branches/Catalyst-Plugin-Session/both/Changes	2008-12-12 21:23:46 UTC (rev 8852)
@@ -2,6 +2,11 @@
 
 0.20    XXX
         - Switch to Module::install
+        - Flash data is now stored inside the session (key "__flash") to avoid
+          duplicate entry errors caused by simultaneous select/insert/delete of
+          flash rows when using DBI as a Store.
+        - Fix session finalization order that caused HTTP responses to be sent
+          before the session is actually finalized and stored in its Store.
 
 0.19    2007-10-08
 

Modified: branches/Catalyst-Plugin-Session/both/lib/Catalyst/Plugin/Session.pm
===================================================================
--- branches/Catalyst-Plugin-Session/finalize_race_condition/lib/Catalyst/Plugin/Session.pm	2008-12-11 16:42:39 UTC (rev 8829)
+++ branches/Catalyst-Plugin-Session/both/lib/Catalyst/Plugin/Session.pm	2008-12-12 21:23:46 UTC (rev 8852)
@@ -170,12 +170,15 @@
         
         my $sid = $c->sessionid;
 
+        my $session_data = $c->_session;
         if (%$flash_data) {
-            $c->store_session_data( "flash:$sid", $flash_data );
+            $session_data->{__flash} = $flash_data;
         }
         else {
-            $c->delete_session_data("flash:$sid");
+            delete $session_data->{__flash};
         }
+        $c->_session($session_data);
+        $c->_save_session;
     }
 }
 
@@ -240,8 +243,11 @@
     $c->_tried_loading_flash_data(1);
 
     if ( my $sid = $c->sessionid ) {
-        if ( my $flash_data = $c->_flash
-            || $c->_flash( $c->get_session_data("flash:$sid") ) )
+
+        my $session_data = $c->session;
+        $c->_flash($session_data->{__flash});
+
+        if ( my $flash_data = $c->_flash )
         {
             $c->_flash_key_hashes({ map { $_ => Object::Signature::signature( \$flash_data->{$_} ) } keys %$flash_data });
             
@@ -689,6 +695,8 @@
 This method is used to invalidate a session. It takes an optional parameter
 which will be saved in C<session_delete_reason> if provided.
 
+NOTE: This method will B<also> delete your flash data.
+
 =item session_delete_reason
 
 This accessor contains a string with the reason a session was deleted. Possible

Modified: branches/Catalyst-Plugin-Session/both/t/03_flash.t
===================================================================
--- branches/Catalyst-Plugin-Session/finalize_race_condition/t/03_flash.t	2008-12-11 16:42:39 UTC (rev 8829)
+++ branches/Catalyst-Plugin-Session/both/t/03_flash.t	2008-12-12 21:23:46 UTC (rev 8852)
@@ -3,9 +3,10 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More tests => 12;
 use Test::MockObject::Extends;
 use Test::Exception;
+use Test::Deep;
 
 my $m;
 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
@@ -19,12 +20,15 @@
         return $key =~ /expire/ ? time() + 1000 : $flash;
     },
 );
+$c->mock("debug" => sub { 0 });
 $c->mock("store_session_data" => sub { $flash = $_[2] });
 $c->mock("delete_session_data" => sub { $flash = {} });
 $c->set_always( _sessionid => "deadbeef" );
 $c->set_always( config     => { session => { expires => 1000 } } );
 $c->set_always( stash      => {} );
 
+is_deeply( $c->session, {}, "nothing in session" );
+
 is_deeply( $c->flash, {}, "nothing in flash" );
 
 $c->flash->{foo} = "moose";
@@ -33,10 +37,14 @@
 
 is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
 
+cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session has __flash with flash data" );
+
 $c->flash(bar => "gorch");
 
 is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
 
+cmp_deeply( $c->session, { __updated => re('^\d+$'), __flash => $c->flash }, "session still has __flash with flash data" );
+
 $c->finalize_body;
 
 is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
@@ -55,6 +63,8 @@
 
 is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
 
+cmp_deeply( $c->session, { __updated => re('^\d+$'), }, "session has empty __flash after clear_flash + finalize" );
+
 $c->flash->{bar} = "gorch";
 
 $c->config->{session}{flash_to_stash} = 1;




More information about the Catalyst-commits mailing list