Permalink
Browse files

sane-ify prepare/finalize_session (in compat compat mode) [beta]

  • Loading branch information...
1 parent 0b73d82 commit 3dfa4c68bc4fb691a9a98588f934f2300d108456 @jrockway committed Feb 10, 2008
@@ -3,6 +3,7 @@ use strict;
use warnings;
use Crypt::Util;
use Class::C3;
+use Carp;
our $VERSION = '0.00_01';
@@ -40,7 +41,7 @@ sub hmac_session_expire_key { # this is not auto-extended like everything else
sub hmac_session {
my $c = shift;
- die 'It is too early/late to call $c->hmac_session' if !$c->{hmac_session};
+ croak 'It is too early/late to call $c->hmac_session' if !$c->{hmac_session};
return $c->{hmac_session};
}
@@ -145,13 +146,21 @@ sub prepare_hmac_session {
$c->log->warn($error) unless $error =~ /No hmac_session cookie/;
$c->_prepare_empty_hmac_session;
}
-
+
+ if($c->can('prepare_session')){
+ $c->prepare_session(@_);
+ }
+
return;
}
sub finalize_hmac_session {
my $c = shift;
+ if($c->can('finalize_session')){
+ $c->finalize_session(@_);
+ }
+
# calc expires
my $perl_expires = $c->_calculate_hmac_session_expiry;
my $cookie_expires = $c->_calculate_hmac_session_cookie_expiry;
@@ -1,6 +1,7 @@
package Catalyst::Plugin::Session::HMAC::Compat;
use strict;
use warnings;
+use Class::C3;
# public API
sub sessionid { goto &Catalyst::Plugin::Session::HMAC::hmac_session_id }
@@ -13,9 +14,8 @@ sub flash { goto &Catalyst::Plugin::Session::HMAC::hmac_flash }
sub clear_flash { goto &Catalyst::Plugin::Session::HMAC::hmac_clear_flash }
sub keep_flash { goto &Catalyst::Plugin::Session::HMAC::hmac_keep_flash }
-# catalyst hooks
-sub prepare_session { goto &Catalyst::Plugin::Session::HMAC::prepare_hmac_session }
-sub finalize_session { goto &Catalyst::Plugin::Session::HMAC::finalize_hmac_session }
+sub prepare_session {}
+sub finalize_session {}
# methods for compat that do nothing.
sub calculate_extended_session_expires {}
View
@@ -1,10 +1,17 @@
package TestApp;
use strict;
use warnings;
+use Class::C3;
use Catalyst qw(Session::HMAC Session::HMAC::Compat);
__PACKAGE__->config->{session}{key} = 'foobar';
__PACKAGE__->setup;
+sub prepare_session {
+ my $c = shift;
+ $c->next::method(@_);
+ $c->session->{request_count}++;
+}
+
1;
@@ -34,4 +34,9 @@ sub get_non_expired_key :Local {
$c->res->body($c->session->{foo});
}
+sub request_count :Local {
+ my ($self, $c) = @_;
+ $c->res->body($c->session->{request_count});
+}
+
1;
View
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 19;
+use Test::More tests => 23;
use URI::Escape;
# setup library path
@@ -28,6 +28,9 @@ $mech->cookie_jar->scan(
ok $orig_expires, 'got expiry from cryptocookie OF DEATH';
+$mech->get_ok('http://localhost/request_count');
+$mech->content_like(qr/2/, '2 requests so far');
+
for(1..3){
$mech->get_ok('http://localhost/increment');
$mech->content_like(qr/count is now $_/);
@@ -53,3 +56,6 @@ $mech->cookie_jar->scan(
ok $new_expires, 'got new expiry';
ok $new_expires > $orig_expires, 'expiry moved forward with time';
+
+$mech->get_ok('http://localhost/request_count');
+$mech->content_like(qr/10/, '10 requests so far');

0 comments on commit 3dfa4c6

Please sign in to comment.