fix tests for clear_flash (mocking was bad)
[catagits/Catalyst-Plugin-Session.git] / lib / Catalyst / Plugin / Session.pm
index 3ad186c..d8ce67e 100644 (file)
@@ -12,7 +12,7 @@ use Digest              ();
 use overload            ();
 use Object::Signature   ();
 
-our $VERSION = "0.11";
+our $VERSION = "0.13";
 
 my @session_data_accessors; # used in delete_session
 BEGIN {
@@ -91,14 +91,22 @@ sub prepare_action {
 sub finalize {
     my $c = shift;
 
+    $c->finalize_session;
+    
+    $c->NEXT::finalize(@_);
+}
+
+sub finalize_session {
+    my $c = shift;
+
+    $c->NEXT::finalize_session;
+
     $c->_save_session_id;
     $c->_save_session;
     $c->_save_flash;
     $c->_save_session_expires;
 
     $c->_clear_session_instance_data;
-
-    $c->NEXT::finalize(@_);
 }
 
 sub _save_session_id {
@@ -247,12 +255,13 @@ sub _expire_session_keys {
 sub _clear_session_instance_data {
     my $c = shift;
     $c->$_(undef) for @session_data_accessors;
+    $c->NEXT::_clear_session_instance_data; # allow other plugins to hook in on this
 }
 
 sub delete_session {
     my ( $c, $msg ) = @_;
 
-    $c->log->debug("Deleting session") if $c->debug;
+    $c->log->debug("Deleting session" . ( defined($msg) ? "($msg)" : '(no reason given)') ) if $c->debug;
 
     # delete the session data
     if ( my $sid = $c->sessionid ) {
@@ -379,6 +388,15 @@ sub flash {
     }
 }
 
+sub clear_flash {
+    my $c = shift;
+    
+    #$c->delete_session_data("flash:" . $c->sessionid); # should this be in here? or delayed till finalization?
+    $c->_flash_key_hashes({});
+    $c->_flash_keep_keys({});
+    $c->_flash({});
+}
+
 sub session_expire_key {
     my ( $c, %keys ) = @_;
 
@@ -630,6 +648,10 @@ of every request.
         }
     }
 
+=item clear_flash
+
+Zap all the keys in the flash regardless of their current state.
+
 =item keep_flash @keys
 
 If you wawnt to keep a flash key for the next request too, even if it hasn't
@@ -786,6 +808,12 @@ Or even more directly, replace C<generate_session_id>:
 Also have a look at L<Crypt::Random> and the various openssl bindings - these
 modules provide APIs for cryptographically secure random data.
 
+=item finalize_session
+
+Clean up the session during C<finalize>.
+
+This clears the various accessors after saving to the store.
+
 =item dump_these
 
 See L<Catalyst/dump_these> - ammends the session data structure to the list of