Accept expires as seconds since new Plack::Response ditches CGI::Simple::Cookie.
Tatsuhiko Miyagawa [Sat, 30 Jan 2010 08:57:23 +0000 (00:57 -0800)]
Added docs and tests for it. Fixes gh-2

lib/Plack/Session/State/Cookie.pm
t/013_cookiestore.t

index 1d6772f..36639db 100644 (file)
@@ -28,7 +28,7 @@ sub expire_session_id {
 
 sub finalize {
     my ($self, $id, $res, $options) = @_;
-    $self->_set_cookie($id, $res, (defined $self->expires ? (expires => $self->expires) : ()));
+    $self->_set_cookie($id, $res, (defined $self->expires ? (expires => time + $self->expires) : ()));
 }
 
 sub _set_cookie {
@@ -99,8 +99,9 @@ be included in the cookie.
 
 =item B<expires>
 
-Expiration time of the cookie, if nothing is supplied then it will
-not be included in the cookie.
+Expiration time of the cookie in seconds, if nothing is supplied then
+it will not be included in the cookie, which means the session expires
+per browser session.
 
 =item B<secure>
 
index cc1e08c..51c2278 100644 (file)
@@ -21,7 +21,7 @@ my $app = sub {
     return [ 200, [], [ "counter=$counter" ] ];
 };
 
-$app = Plack::Middleware::Session::Cookie->wrap($app, secret => "foobar");
+$app = Plack::Middleware::Session::Cookie->wrap($app, secret => "foobar", expires => 3600);
 
 my $ua = LWP::UserAgent->new;
 $ua->cookie_jar( HTTP::Cookies->new );
@@ -31,9 +31,11 @@ test_psgi ua => $ua, app => $app, client => sub {
 
     my $res = $cb->(GET "/");
     is $res->content, "counter=0";
+    like $res->header('Set-Cookie'), qr/expires=/;
 
     $res = $cb->(GET "/");
     is $res->content, "counter=1";
+    like $res->header('Set-Cookie'), qr/expires=/;
 
     $res = $cb->(GET "/");
     is $res->content, "counter=2";