From: Sebastian Riedel Date: Mon, 14 Nov 2005 18:45:07 +0000 (+0000) Subject: Perltidy'ed Catalyst::Plugin::Session::* X-Git-Tag: v0.01~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session-State-Cookie.git;a=commitdiff_plain;h=58730edcb664fc621cbb907b477d037c5c8576fa;hp=724a61732700d4e8e7de83b3665c7611dafc204b Perltidy'ed Catalyst::Plugin::Session::* --- diff --git a/lib/Catalyst/Plugin/Session/State/Cookie.pm b/lib/Catalyst/Plugin/Session/State/Cookie.pm index ebe362b..51727e2 100644 --- a/lib/Catalyst/Plugin/Session/State/Cookie.pm +++ b/lib/Catalyst/Plugin/Session/State/Cookie.pm @@ -19,37 +19,38 @@ sub setup_session { sub finalize_cookies { my $c = shift; - if ( $c->sessionid) { - $c->update_session_cookie( $c->make_session_cookie ); - } + if ( $c->sessionid ) { + $c->update_session_cookie( $c->make_session_cookie ); + } return $c->NEXT::finalize_cookies(@_); } sub update_session_cookie { - my ( $c, $updated ) = @_; + my ( $c, $updated ) = @_; my $cookie_name = $c->config->{session}{cookie_name}; - $c->response->cookies->{$cookie_name} = $updated; + $c->response->cookies->{$cookie_name} = $updated; } sub make_session_cookie { - my $c = shift; - - my $cfg = $c->config->{session}; - my $cookie = { - value => $c->sessionid, - ($cfg->{cookie_domain} ? (domain => $cfg->{cookie_domain}) : ()), - }; - - if ( exists $cfg->{cookie_expires} ) { - if ( my $ttl = $cfg->{cookie_expires} ) { - $cookie->{expires} = time() + $ttl; - } # else { cookie is non-persistent } - } else { - $cookie->{expires} = $c->session->{__expires}; - } + my $c = shift; + + my $cfg = $c->config->{session}; + my $cookie = { + value => $c->sessionid, + ( $cfg->{cookie_domain} ? ( domain => $cfg->{cookie_domain} ) : () ), + }; + + if ( exists $cfg->{cookie_expires} ) { + if ( my $ttl = $cfg->{cookie_expires} ) { + $cookie->{expires} = time() + $ttl; + } # else { cookie is non-persistent } + } + else { + $cookie->{expires} = $c->session->{__expires}; + } - return $cookie; + return $cookie; } sub prepare_cookies { diff --git a/t/basic.t b/t/basic.t index 526aeba..66711dd 100644 --- a/t/basic.t +++ b/t/basic.t @@ -58,9 +58,11 @@ $res->clear; can_ok( $m, "finalize_cookies" ); $cxt->finalize_cookies; -{ local $TODO = "This check is a pain to write, should be done by catalyst itself"; -ok( !$res->called("cookies"), - "response cookie was not set since res cookie is already there" ); +{ + local $TODO = + "This check is a pain to write, should be done by catalyst itself"; + ok( !$res->called("cookies"), + "response cookie was not set since res cookie is already there" ); } $cxt->clear; diff --git a/t/live_app.t b/t/live_app.t index 5852b94..db8afdb 100644 --- a/t/live_app.t +++ b/t/live_app.t @@ -29,9 +29,9 @@ BEGIN { sub stream : Local { my ( $self, $c ) = @_; - my $count = ++$c->session->{counter}; + my $count = ++$c->session->{counter}; $c->res->write("hit number "); - $c->res->write( $count ); + $c->res->write($count); } __PACKAGE__->setup; @@ -41,24 +41,24 @@ use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/; my $m = Test::WWW::Mechanize::Catalyst->new; -$m->get_ok("http://foo.com/stream", "get page"); -$m->content_contains("hit number 1", "session data created"); +$m->get_ok( "http://foo.com/stream", "get page" ); +$m->content_contains( "hit number 1", "session data created" ); my $expired; -$m->cookie_jar->scan(sub { $expired = $_[8] }); +$m->cookie_jar->scan( sub { $expired = $_[8] } ); -$m->get_ok("http://foo.com/page", "get page"); -$m->content_contains("hit number 2", "session data restored"); +$m->get_ok( "http://foo.com/page", "get page" ); +$m->content_contains( "hit number 2", "session data restored" ); -$m->get_ok("http://foo.com/stream", "get stream"); -$m->content_contains("hit number 3", "session data restored"); +$m->get_ok( "http://foo.com/stream", "get stream" ); +$m->content_contains( "hit number 3", "session data restored" ); sleep 1; -$m->get_ok("http://foo.com/page", "get stream"); -$m->content_contains("hit number 4", "session data restored"); +$m->get_ok( "http://foo.com/page", "get stream" ); +$m->content_contains( "hit number 4", "session data restored" ); my $updated_expired; -$m->cookie_jar->scan(sub { $updated_expired = $_[8] }); +$m->cookie_jar->scan( sub { $updated_expired = $_[8] } ); -cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended"); +cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" );