version bump
[catagits/Catalyst-Plugin-Session.git] / lib / Catalyst / Plugin / Session.pm
index 887fb28..f203e28 100644 (file)
@@ -11,8 +11,9 @@ use Catalyst::Exception ();
 use Digest              ();
 use overload            ();
 use Object::Signature   ();
+use Carp;
 
-our $VERSION = "0.12";
+our $VERSION = "0.19";
 
 my @session_data_accessors; # used in delete_session
 BEGIN {
@@ -68,7 +69,7 @@ sub setup_session {
 
     %$cfg = (
         expires        => 7200,
-        verify_address => 1,
+        verify_address => 0,
         %$cfg,
     );
 
@@ -88,12 +89,22 @@ sub prepare_action {
     $c->NEXT::prepare_action(@_);
 }
 
+sub finalize_headers {
+    my $c = shift;
+
+    # fix cookie before we send headers
+    $c->_save_session_expires;
+
+    return $c->NEXT::finalize_headers(@_);
+}
+
 sub finalize {
     my $c = shift;
+    my $ret = $c->NEXT::finalize(@_);
 
+    # then finish the rest
     $c->finalize_session;
-    
-    $c->NEXT::finalize(@_);
+    return $ret;
 }
 
 sub finalize_session {
@@ -104,7 +115,6 @@ sub finalize_session {
     $c->_save_session_id;
     $c->_save_session;
     $c->_save_flash;
-    $c->_save_session_expires;
 
     $c->_clear_session_instance_data;
 }
@@ -380,17 +390,36 @@ sub keep_flash {
     (@{$href}{@keys}) = ((undef) x @keys);
 }
 
-sub flash {
+sub _flash_data { 
     my $c = shift;
     $c->_flash || $c->_load_flash || do {
         $c->create_session_id_if_needed;
         $c->_flash( {} );
+    };
+}
+
+sub _set_flash {
+    my $c = shift;
+    if (@_) {
+        my $items = @_ > 1 ? {@_} : $_[0];
+        croak('flash takes a hash or hashref') unless ref $items;
+        @{ $c->_flash }{ keys %$items } = values %$items;
     }
 }
 
+sub flash {
+    my $c = shift;
+    $c->_flash_data;
+    $c->_set_flash(@_);
+    return $c->_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({});
 }
 
@@ -563,7 +592,7 @@ made by the same client.
 
 This plugin links the two pieces together.
 
-=head1 RECCOMENDED BACKENDS
+=head1 RECOMENDED BACKENDS
 
 =over 4
 
@@ -723,10 +752,15 @@ It's only effect is if the (off by default) C<flash_to_stash> configuration
 parameter is on - then it will copy the contents of the flash to the stash at
 prepare time.
 
+=item finalize_headers
+
+This method is extended and will extend the expiry time before sending
+the response.
+
 =item finalize
 
-This method is extended and will extend the expiry time, as well as persist the
-session data if a session exists.
+This method is extended and will call finalize_session after the other
+finalizes run.  Here we persist the session data if a session exists.
 
 =item initialize_session_data
 
@@ -816,6 +850,27 @@ This clears the various accessors after saving to the store.
 See L<Catalyst/dump_these> - ammends the session data structure to the list of
 dumped objects if session ID is defined.
 
+
+=item calculate_extended_session_expires
+
+=item calculate_initial_session_expires
+
+=item create_session_id_if_needed
+
+=item delete_session_id
+
+=item extend_session_expires
+
+=item extend_session_id
+
+=item get_session_id
+
+=item reset_session_expires
+
+=item session_is_valid
+
+=item set_session_id
+
 =back
 
 =head1 USING SESSIONS DURING PREPARE
@@ -859,6 +914,8 @@ hours).
 When true, C<<$c->request->address>> will be checked at prepare time. If it is
 not the same as the address that initiated the session, the session is deleted.
 
+Defaults to false.
+
 =item flash_to_stash
 
 This option makes it easier to have actions behave the same whether they were