I finally spent time looking at why this plugin didn't work. I use
session cookies and the module didn't work with session cookies.
Here's a failing (now passing) test case and patch against svn.
--
Bill Moseley
[EMAIL PROTECTED]
Index: t/session_cookie.t
===================================================================
--- t/session_cookie.t (revision 0)
+++ t/session_cookie.t (revision 0)
@@ -0,0 +1,127 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use HTTP::Date;
+
+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 }
+ or plan skip_all =>
+ "Test::WWW::Mechanize::Catalyst is required for this test";
+
+ plan tests => 13;
+}
+
+my $cookie_name = 'test_session';
+my $ttl = 60 * 60; # Remember me for an hour
+
+{
+ package SessionTest;
+ use strict;
+ use warnings;
+
+ use Catalyst qw/
+ Session::DynamicExpiry
+ Session
+ Session::Store::Dummy
+ Session::State::Cookie
+ /;
+
+ my $config = {
+ session => {
+ cookie_name => $cookie_name,
+ cookie_expires => 0, # Use session cookies
+ },
+ };
+
+ sub counter : Path( '/foo/counter' ) {
+ my ( $self, $c ) = @_;
+ $c->res->body( ++$c->session->{counter} );
+ }
+
+ sub remember_me : Path( '/foo/remember_me' ) {
+ my ( $self, $c ) = @_;
+ $c->session_time_to_live( $ttl );
+ $c->forward("counter");
+ }
+
+ __PACKAGE__->config( $config );
+ __PACKAGE__->setup;
+}
+
+
+
+
+use Test::WWW::Mechanize::Catalyst 'SessionTest';
+
+ my $m = Test::WWW::Mechanize::Catalyst->new;
+
+ # Add an initial bad cookie for good measure.
+ $m->cookie_jar->set_cookie(
+ 0, # version
+ $cookie_name, # key
+ time(), # invalid session id
+ '/', # path
+ '.local', # domain # is this portable?
+ 80, # port
+ 0, # path_spec
+ 0, # secure
+ 100, # max_age ttl seconds
+ 0, # discard
+ );
+
+ $m->get_ok("http://localhost/foo/counter");
+ $m->content_is( 1, "counter worked" );
+
+
+
+
+ $m->get_ok("http://localhost/foo/counter");
+ $m->content_is( 2, "counter worked" );
+
+ my $cookie_expires = cookie_expires( $m->response );
+
+
+ ok( !defined($cookie_expires), "have session cookie (no expires)" );
+
+
+
+ # This sets the session value.
+
+ $m->get_ok("http://localhost/foo/remember_me");
+ $m->content_is( 3, "counter worked" );
+
+ my $long_cookie_expires = cookie_expires( $m->response );
+
+ ok( defined($long_cookie_expires), "expiry time defined" );
+
+ cmp_ok( $long_cookie_expires, '>', time() + $ttl - 20, "The expire time is set");
+
+
+ # Now a request to see if the long time is still there
+
+ $m->get_ok("http://localhost/foo/counter");
+ $m->content_is( 4, "counter worked" );
+
+ $long_cookie_expires = cookie_expires( $m->response );
+
+ ok( defined($long_cookie_expires), "expiry time defined" );
+
+ cmp_ok( $long_cookie_expires, '>', time() + $ttl - 20, "The expire time is still set");
+
+sub cookie_expires {
+ my $response = shift;
+
+ my $c = CGI::Simple::Cookie->parse( $response->header( 'Set-Cookie' ) )->{expires};
+
+ return unless $c;
+
+ return str2time( $c->value );
+}
+
Index: lib/Catalyst/Plugin/Session/DynamicExpiry.pm
===================================================================
--- lib/Catalyst/Plugin/Session/DynamicExpiry.pm (revision 7224)
+++ lib/Catalyst/Plugin/Session/DynamicExpiry.pm (working copy)
@@ -6,7 +6,7 @@
use NEXT;
-our $VERSION='0.03';
+our $VERSION='0.04';
__PACKAGE__->mk_accessors(qw/_session_time_to_live/);
@@ -44,6 +44,21 @@
return $c->NEXT::calculate_extended_session_expires( @_ );
}
+# Handle the situation when using session cookies (cookie_expiers == 0)
+sub calculate_session_cookie_expires {
+ my $c = shift;
+ my $expires = $c->config->{session}{cookie_expires};
+ my $ttl = $c->session_time_to_live;
+
+ # Return our ttl if it's set and configured for session cookies
+
+ return $ttl && defined $expires && $expires == 0
+ ? time() + $ttl
+ : $c->NEXT::calculate_session_cookie_expires(@_);
+}
+
+
+
sub _save_session {
my $c = shift;
Index: Changes
===================================================================
--- Changes (revision 7224)
+++ Changes (working copy)
@@ -1,5 +1,9 @@
Revision history for Perl extension Catalyst::Plugin::Session::DynamicExpiry
+0.04
+ - Added failing test for session cookie
+ - Added calculate_session_cookie_expires() to fix above failing test.
+
0.03 2007-09-06
- Added plugin order warning
- Switch to module::install
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/