From: Tomas Doran Date: Tue, 6 Oct 2009 20:25:49 +0000 (+0100) Subject: Update for new Catalyst version and upcoming new Session plugin version X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=effd624415454b9835b0f269b158356942a0eea9;hp=f43b63384fef69d98ad5b7e15f42a21a9279a8de;p=catagits%2FCatalyst-Plugin-Session-State-Stash.git Update for new Catalyst version and upcoming new Session plugin version --- diff --git a/Changes b/Changes index 1d3fb18..3263428 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ Revision history for Catalyst-Plugin-Session-State-Stash -0.01 Date/time +0.11 UNRELEASED + - Update to be able to use the new 'Plugin::Session' config key + as the rest of the Session infrastructure is moving to that. + - Move actions out of the application class for TestApp as this + warns with the latest Catalyst. + +0.10 19 Apr 2009 First version, released on an unsuspecting world. diff --git a/lib/Catalyst/Plugin/Session/State/Stash.pm b/lib/Catalyst/Plugin/Session/State/Stash.pm index 392609a..438b910 100644 --- a/lib/Catalyst/Plugin/Session/State/Stash.pm +++ b/lib/Catalyst/Plugin/Session/State/Stash.pm @@ -13,9 +13,10 @@ BEGIN { __PACKAGE__->mk_accessors(qw/_deleted_session_id _prepared/) } sub _stash_key_components { my ($c) = @_; - return ($c->config->{session}->{stash_delim}) ? - split $c->config->{session}->{stash_delim}, $c->config->{session}->{stash_key} : - $c->config->{session}->{stash_key}; + my $config = $c->config->{'Plugin::Session'} || $c->config->{'session'}; + return ($config->{stash_delim}) ? + split $config->{stash_delim}, $config->{stash_key} : + $config->{stash_key}; } sub _get_session { @@ -35,7 +36,9 @@ sub _set_session { sub setup_session { my $c = shift; - $c->config->{session}->{stash_key} + $c->config->{'Plugin::Session'} + and return $c->config->{'Plugin::Session'}->{stash_key} |= '_session'; + $c->config->{'session'}->{stash_key} ||= '_session'; } @@ -168,7 +171,7 @@ How long the session should last in seconds. For example, you could stick this in MyApp.pm: - __PACKAGE__->config( session => { + __PACKAGE__->config( 'Plugin::Session' => { stash_key => 'session_id', }); diff --git a/t/04-basic.t b/t/04-basic.t index a5d0bdc..99a2e76 100644 --- a/t/04-basic.t +++ b/t/04-basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 10; use Test::MockObject; use Test::MockObject::Extends; @@ -27,19 +27,30 @@ can_ok( $m, "setup_session" ); $cxt->setup_session; -is( $cxt->config->{session}{stash_key}, +is( $cxt->config->{'session'}{stash_key}, '_session', "default cookie name is set" ); can_ok( $m, "get_session_id" ); ok( !$cxt->get_session_id, "no session id yet"); -$cxt->set_always( stash => { '_session' => {id => 1}, 'session_id' => {id => 2} } ); +$cxt->set_always( stash => { '_session' => {id => 1}, 'session_id' => {id => 2}, 'other_thing' => { id => 3 } } ); is( $cxt->get_session_id, "1", "Pull newfound session id" ); -$cxt->config->{session}{stash_key} = "session_id"; +$cxt->config->{'session'}{stash_key} = "session_id"; is( $cxt->get_session_id, "2", "Pull session id from second key" ); -can_ok( $m, "set_session_id" ); \ No newline at end of file +can_ok( $m, "set_session_id" ); + +# Check forwards config compatibility.. +$cxt->config->{'Plugin::Session'} = {}; +$cxt->setup_session; + +is( $cxt->config->{'Plugin::Session'}{stash_key}, + '_session', "default cookie name is set when new stash key used" ); + +$cxt->config->{'Plugin::Session'}{stash_key} = "other_thing"; + +is( $cxt->get_session_id, "3", "Pull session id from key in new config" ); diff --git a/t/05-live.t b/t/05-live.t index 7c1f1af..8d36caf 100644 --- a/t/05-live.t +++ b/t/05-live.t @@ -3,6 +3,9 @@ use strict; use warnings; +use FindBin qw/$Bin/; +use lib "$Bin/lib"; + use URI::Escape; use Test::More; @@ -14,58 +17,6 @@ BEGIN { plan skip_all => 'Test::WWW::Mechanize::Catalyst >= 0.40 required' if $Test::WWW::Mechanize::Catalyst::VERSION < 0.40; } -{ - - package TestApp; - use Catalyst qw/ - Session - Session::Store::Dummy - Session::State::Stash - -Debug - /; - - sub start_session : Local { - my ( $self, $c ) = @_; - $c->session->{counter} = 1; - $c->res->body($c->stash->{_session}->{id}); - } - - sub page : Local { - my ( $self, $c, $id ) = @_; - $c->stash ( '_session' => {id => $id} ); - $c->res->body( "Hi! hit number " . ++$c->session->{counter} ); - } - - sub stream : Local { - my ( $self, $c, $id ) = @_; - $c->stash ( '_session' => {id => $id} ); - my $count = ++$c->session->{counter}; - $c->res->body("hit number $count"); - } - - sub deleteme : Local { - my ( $self, $c, $id ) = @_; - $c->stash ( '_session' => {id => $id} ); - my $id2 = $c->get_session_id; - $c->delete_session; - my $id3 = $c->get_session_id; - - # In the success case, print 'Pass' - if (defined $id2 && - defined $id3 && - $id2 ne $id3 - ) { - $c->res->body('PASS'); - } else { - #In the failure case, provide debug info - $id3 ||= ''; - $c->res->body("FAIL: Matching ids, $id3"); - } - } - - __PACKAGE__->setup; -} - use Test::WWW::Mechanize::Catalyst qw/TestApp/; my $m = Test::WWW::Mechanize::Catalyst->new; diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm new file mode 100644 index 0000000..89f03e5 --- /dev/null +++ b/t/lib/TestApp.pm @@ -0,0 +1,15 @@ +package TestApp; +use strict; +use warnings; + +use base qw/Catalyst/; + +use Catalyst qw/ + Session + Session::Store::Dummy + Session::State::Stash + /; + +__PACKAGE__->setup; + +1; diff --git a/t/lib/TestApp/Controller/Root.pm b/t/lib/TestApp/Controller/Root.pm new file mode 100644 index 0000000..b4efb1f --- /dev/null +++ b/t/lib/TestApp/Controller/Root.pm @@ -0,0 +1,47 @@ +package TestApp::Controller::Root; +use strict; +use warnings; +use base qw/Catalyst::Controller/; + +__PACKAGE__->config( namespace => '' ); + +sub start_session : Local { + my ( $self, $c ) = @_; + $c->session->{counter} = 1; + $c->res->body($c->stash->{_session}->{id}); +} + +sub page : Local { + my ( $self, $c, $id ) = @_; + $c->stash ( '_session' => {id => $id} ); + $c->res->body( "Hi! hit number " . ++$c->session->{counter} ); +} + +sub stream : Local { + my ( $self, $c, $id ) = @_; + $c->stash ( '_session' => {id => $id} ); + my $count = ++$c->session->{counter}; + $c->res->body("hit number $count"); +} + +sub deleteme : Local { + my ( $self, $c, $id ) = @_; + $c->stash ( '_session' => {id => $id} ); + my $id2 = $c->get_session_id; + $c->delete_session; + my $id3 = $c->get_session_id; + + # In the success case, print 'Pass' + if (defined $id2 && + defined $id3 && + $id2 ne $id3 + ) { + $c->res->body('PASS'); + } else { + #In the failure case, provide debug info + $id3 ||= ''; + $c->res->body("FAIL: Matching ids, $id3"); + } +} + +1;