version bump
[catagits/Catalyst-Plugin-Session.git] / lib / Catalyst / Plugin / Session.pm
index d4a4517..f203e28 100644 (file)
@@ -11,8 +11,9 @@ use Catalyst::Exception ();
 use Digest              ();
 use overload            ();
 use Object::Signature   ();
+use Carp;
 
-our $VERSION = "0.13";
+our $VERSION = "0.19";
 
 my @session_data_accessors; # used in delete_session
 BEGIN {
@@ -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,14 +390,30 @@ 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;
     
@@ -566,7 +592,7 @@ made by the same client.
 
 This plugin links the two pieces together.
 
-=head1 RECCOMENDED BACKENDS
+=head1 RECOMENDED BACKENDS
 
 =over 4
 
@@ -726,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
 
@@ -819,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