Merge branch 'master' into tags/0.32 tags/0.32 mirror/tags/0.32 v0.32
Devin Austin [Fri, 30 Mar 2012 21:32:41 +0000 (14:32 -0700)]
Changes
MANIFEST.SKIP
Makefile.PL
lib/Catalyst/Plugin/Session.pm
lib/Catalyst/Plugin/Session/Test/Store.pm
t/live_verify_address.t

diff --git a/Changes b/Changes
index a84b9e0..f128488 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,12 @@
 Revision history for Perl extension Catalyst::Plugin::Session
 
+0.34 2012-03-30
+        - Fixed up t/live_verify_address.t per https://rt.cpan.org/Ticket/Display.html?id=71142
+
+0.33 2012-03-08
+        - Note that flash is deprecated / not recommended due to it's
+          inherent races. Point out Catalyst::Plugin::StatusMessage instead
+
 0.32 2011-06-08
         - Fix handling with enables verify_address and add related test
 
index ef8ebaf..94c816f 100644 (file)
@@ -1,3 +1,5 @@
+\bMYMETA.yml\b
+
 # Avoid version control files.
 \bRCS\b
 \bCVS\b
index 69bbbbf..17790c7 100644 (file)
@@ -30,8 +30,9 @@ requires 'Test::More' => '0.88';
 
 test_requires 'Test::Deep';
 test_requires 'Test::Exception';
-
-resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Plugin-Session/0.00/trunk/';
+test_requires 'Test::WWW::Mechanize::PSGI';
+test_requires 'Plack::Middleware::ForceEnv';
+resources repository => 'git://git.shadowcat.co.uk/catagits/Catalyst-Plugin-Session.git';
 
 WriteAll;
 
index 69607fa..908d14a 100644 (file)
@@ -13,7 +13,7 @@ use Carp;
 
 use namespace::clean -except => 'meta';
 
-our $VERSION = '0.32';
+our $VERSION = '0.34';
 $VERSION = eval $VERSION;
 
 my @session_data_accessors; # used in delete_session
@@ -102,8 +102,10 @@ sub prepare_action {
 sub finalize_headers {
     my $c = shift;
 
-    # fix cookie before we send headers
-    $c->_save_session_expires;
+    # Force extension of session_expires before finalizing headers, so a possible cookie will be
+    # up to date. First call to session_expires will extend the expiry, subsequent calls will
+    # just return the previously extended value.
+    $c->session_expires;
 
     return $c->maybe::next::method(@_);
 }
@@ -124,6 +126,7 @@ sub finalize_session {
 
     $c->maybe::next::method(@_);
 
+    $c->_save_session_expires;
     $c->_save_session_id;
     $c->_save_session;
     $c->_save_flash;
@@ -724,6 +727,15 @@ $c->flash (thus allowing multiple redirections), and the policy is to delete
 all the keys which haven't changed since the flash data was loaded at the end
 of every request.
 
+Note that use of the flash is an easy way to get data across requests, but
+it's also strongly disrecommended, due it it being inherently plagued with
+race conditions. This means that it's unlikely to work well if your
+users have multiple tabs open at once, or if your site does a lot of AJAX
+requests.
+
+L<Catalyst::Plugin::StatusMessage> is the recommended alternative solution,
+as this doesn't suffer from these issues.
+
     sub moose : Local {
         my ( $self, $c ) = @_;
 
@@ -789,7 +801,7 @@ expiry time for the whole session).
 
 For example:
 
-    __PACKAGE__->config('Plugin::Session' => { expires => 10000000000 }); # "forever" 
+    __PACKAGE__->config('Plugin::Session' => { expires => 10000000000 }); # "forever"
     (NB If this number is too large, Y2K38 breakage could result.)
 
     # later
@@ -1132,6 +1144,10 @@ Kent Fredric (kentnl)
 
 And countless other contributers from #catalyst. Thanks guys!
 
+=head1 Contributors
+
+Devin Austin (dhoss) <dhoss@cpan.org>
+
 =head1 COPYRIGHT & LICENSE
 
     Copyright (c) 2005 the aforementioned authors. All rights
index 52e6c96..d9b7ba3 100644 (file)
@@ -92,7 +92,8 @@ sub import {
 
         @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
 
-        { __PACKAGE__->setup; }; # INSANE HACK 
+        { __PACKAGE__->setup; }; # Extra block here is an INSANE HACK to get inlined constructor
+                                 # (i.e. to make B::Hooks::EndOfScope fire)
     }
 
     {
@@ -130,7 +131,7 @@ sub import {
 
         @{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
 
-        { __PACKAGE__->setup; }; # INSANE HACK
+        { __PACKAGE__->setup; }; # INSANE HACK (the block - as above)
     }
 
     use Test::More;
index 7b04db6..43c52c9 100644 (file)
@@ -4,29 +4,32 @@ use strict;
 use warnings;
 
 use Test::More;
-
 BEGIN {
     eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
       or plan skip_all =>
       "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
 
     eval {
-        require Test::WWW::Mechanize::Catalyst;
-        Test::WWW::Mechanize::Catalyst->VERSION(0.51);
+        require Test::WWW::Mechanize::PSGI;
+        #Test::WWW::Mechanize::Catalyst->VERSION(0.51);
     }
     or plan skip_all =>
-        'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
+        'Test::WWW::Mechanize::PSGI is required for this test';
 
     plan tests => 12;
 }
 
 use lib "t/lib";
-use Test::WWW::Mechanize::Catalyst "SessionTestApp";
+use Test::WWW::Mechanize::PSGI;
+use SessionTestApp;
+my $ua = Test::WWW::Mechanize::PSGI->new(
+  app => SessionTestApp->psgi_app(@_),
+  cookie_jar => {}
+);
 
 # Test without delete __address
 local $ENV{REMOTE_ADDR} = "192.168.1.1";
 
-my $ua = Test::WWW::Mechanize::Catalyst->new( {} );
 $ua->get_ok( "http://localhost/login" );
 $ua->content_contains('logged in');
 
@@ -34,11 +37,20 @@ $ua->get_ok( "http://localhost/set_session_variable/logged/in" );
 $ua->content_contains('session variable set');
 
 
-# Change Client 
-local $ENV{REMOTE_ADDR} = "192.168.1.2";
-
-$ua->get_ok( "http://localhost/get_session_variable/logged");
-$ua->content_contains('VAR_logged=n.a.');
+# Change Client
+#local $ENV{REMOTE_ADDR} = "192.168.1.2";
+use Plack::Builder;
+my $app = SessionTestApp->psgi_app(@_);
+builder {
+  enable 'ForceEnv' => REMOTE_ADDR => "192.168.1.2";
+  $app;
+};
+my $ua2 = Test::WWW::Mechanize::PSGI->new(
+    app => $app,
+    cookie_jar => {}
+);
+$ua2->get_ok( "http://localhost/get_session_variable/logged");
+$ua2->content_contains('VAR_logged=n.a.');
 
 # Inital Client
 local $ENV{REMOTE_ADDR} = "192.168.1.1";
@@ -49,7 +61,7 @@ $ua->content_contains('logged in (without address)');
 $ua->get_ok( "http://localhost/set_session_variable/logged/in" );
 $ua->content_contains('session variable set');
 
-# Change Client 
+# Change Client
 local $ENV{REMOTE_ADDR} = "192.168.1.2";
 
 $ua->get_ok( "http://localhost/get_session_variable/logged" );