Middleware added, cookie state added, and example psgi app
[catagits/Web-Session.git] / lib / Plack / Session / State / Cookie.pm
1 package Plack::Session::State::Cookie;
2 use strict;
3 use warnings;
4
5 use parent 'Plack::Session::State';
6
7 use Plack::Util::Accessor qw[ path domain expires secure ];
8
9 sub expire_session_id {
10     my ($self, $id) = @_;
11     $self->SUPER::expire_session_id( $id );
12     $self->expires( 0 );
13 }
14
15 sub extract {
16     my ($self, $request) = @_;
17     $self->check_expired( ( $request->cookie( $self->session_key ) || return )->value );
18 }
19
20 sub finalize {
21     my ($self, $id, $response) = @_;
22     $response->cookies->{ $self->session_key } = +{
23         value => $id,
24         path  => ($self->path || '/'),
25         ( $self->domain  ? ( domain  => $self->domain  ) : () ),
26         ( $self->expires ? ( expires => $self->expires ) : () ),
27         ( $self->secure  ? ( secure  => $self->secure  ) : () ),
28     };
29 }
30
31 1;