[Catalyst-commits] r6934 - in trunk/Catalyst-Plugin-Session:
lib/Catalyst/Plugin t
jrockway at dev.catalyst.perl.org
jrockway at dev.catalyst.perl.org
Sat Sep 22 03:40:14 GMT 2007
Author: jrockway
Date: 2007-09-22 03:40:12 +0100 (Sat, 22 Sep 2007)
New Revision: 6934
Added:
trunk/Catalyst-Plugin-Session/t/06_finalize.t
Modified:
trunk/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm
trunk/Catalyst-Plugin-Session/t/03_flash.t
Log:
move finalization to finalize but keep header munging in finalize_headers; re-add finalize test; update POD
Modified: trunk/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm
===================================================================
--- trunk/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm 2007-09-22 00:55:53 UTC (rev 6933)
+++ trunk/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm 2007-09-22 02:40:12 UTC (rev 6934)
@@ -92,11 +92,21 @@
sub finalize_headers {
my $c = shift;
- $c->finalize_session;
+ # 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;
+ return $ret;
+}
+
sub finalize_session {
my $c = shift;
@@ -105,7 +115,6 @@
$c->_save_session_id;
$c->_save_session;
$c->_save_flash;
- $c->_save_session_expires;
$c->_clear_session_instance_data;
}
@@ -745,9 +754,14 @@
=item finalize_headers
-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 extend the expiry time before sending
+the response.
+=item finalize
+
+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
This method will initialize the internal structure of the session, and is
@@ -836,6 +850,27 @@
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
Modified: trunk/Catalyst-Plugin-Session/t/03_flash.t
===================================================================
--- trunk/Catalyst-Plugin-Session/t/03_flash.t 2007-09-22 00:55:53 UTC (rev 6933)
+++ trunk/Catalyst-Plugin-Session/t/03_flash.t 2007-09-22 02:40:12 UTC (rev 6934)
@@ -29,7 +29,7 @@
$c->flash->{foo} = "moose";
-$c->finalize_headers;
+$c->finalize;
is_deeply( $c->flash, { foo => "moose" }, "one key in flash" );
@@ -37,21 +37,21 @@
is_deeply( $c->flash, { foo => "moose", bar => "gorch" }, "two keys in flash" );
-$c->finalize_headers;
+$c->finalize;
is_deeply( $c->flash, { bar => "gorch" }, "one key in flash" );
-$c->finalize_headers;
+$c->finalize;
$c->flash->{test} = 'clear_flash';
-$c->finalize_headers;
+$c->finalize;
$c->clear_flash();
is_deeply( $c->flash, {}, "nothing in flash after clear_flash" );
-$c->finalize_headers;
+$c->finalize;
is_deeply( $c->flash, {}, "nothing in flash after finalize after clear_flash" );
@@ -59,7 +59,7 @@
$c->config->{session}{flash_to_stash} = 1;
-$c->finalize_headers;
+$c->finalize;
$c->prepare_action;
is_deeply( $c->stash, { bar => "gorch" }, "flash copied to stash" );
Copied: trunk/Catalyst-Plugin-Session/t/06_finalize.t (from rev 6691, trunk/Catalyst-Plugin-Session/t/06_finalize.t)
===================================================================
--- trunk/Catalyst-Plugin-Session/t/06_finalize.t (rev 0)
+++ trunk/Catalyst-Plugin-Session/t/06_finalize.t 2007-09-22 02:40:12 UTC (rev 6934)
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+ if ( eval { require Catalyst::Plugin::Session::State::Cookie } ) {
+ plan tests => 3;
+ } else {
+ plan skip_all => "Catalyst::Plugin::Session::State::Cookie required";
+ }
+}
+
+my $finalized = 0;
+
+{
+ package TestPlugin;
+ BEGIN { $INC{"TestPlugin.pm"} = 1 } # nasty hack for 5.8.6
+
+ sub finalize_session { $finalized = 1 }
+
+ sub finalize { die "already finalized_session()" if $finalized }
+
+ # Structure inheritance so TestPlugin->finalize() is called *after*
+ # Catalyst::Plugin::Session->finalize()
+ package TestApp;
+
+ use Catalyst qw/
+ Session Session::Store::Dummy Session::State::Cookie +TestPlugin
+ /;
+ __PACKAGE__->setup;
+}
+
+BEGIN { use_ok('Catalyst::Plugin::Session') }
+
+my $c = TestApp->new;
+eval { $c->finalize };
+ok(!$@, "finalize_session() called after all other finalize() methods");
+ok($finalized, "finalize_session() called");
More information about the Catalyst-commits
mailing list