add Catalyst::Plugin::Session::Tutorial
[catagits/Catalyst-Plugin-Session.git] / lib / Catalyst / Plugin / Session.pm
index f306997..f54cd60 100644 (file)
@@ -12,7 +12,7 @@ use Digest              ();
 use overload            ();
 use Object::Signature   ();
 
-our $VERSION = "0.04";
+our $VERSION = "0.05";
 
 my @session_data_accessors; # used in delete_session
 BEGIN {
@@ -120,15 +120,15 @@ sub _save_flash {
     my $c = shift;
 
     if ( my $sid = $c->_sessionid ) {
-        my $flash_data = $c->_flash || {};
+        if ( my $flash_data = $c->_flash ) {
+            delete @{$flash_data}{ @{ $c->_flash_stale_keys || [] } };
 
-        delete @{$flash_data}{ @{ $c->_flash_stale_keys || [] } };
-
-        if (%$flash_data) {    # damn 'my' declarations
-            $c->store_session_data( "flash:$sid", $flash_data );
-        }
-        else {
-            $c->delete_session_data("flash:$sid");
+            if (%$flash_data) {
+                $c->store_session_data( "flash:$sid", $flash_data );
+            }
+            else {
+                $c->delete_session_data("flash:$sid");
+            }
         }
     }
 }
@@ -245,6 +245,10 @@ sub sessionid {
     my $c = shift;
 
     if (@_) {
+        if($c->_sessionid()) {
+            $c->log->warn('Session ID already set, ignoring.');
+            return $c->_sessionid();
+        }
         if ( $c->validate_session_id( my $sid = shift ) ) {
             $c->_sessionid($sid);
             return unless defined wantarray;
@@ -493,7 +497,12 @@ L</CONFIGURATION>). This is used when creating a new session.
 =item flash
 
 This is like Ruby on Rails' flash data structure. Think of it as a stash that
-lasts a single redirect, not only a forward.
+lasts for longer than one request, letting you redirect instead of forward.
+
+The flash data will be cleaned up only on requests on which actually use
+$c->flash (thus allowing multiple redirections), and the policy is to delete
+all the keys which were present at the time the data was loaded just before the
+data is saved.
 
     sub moose : Local {
         my ( $self, $c ) = @_;