tests for State::Cookie
[catagits/Web-Session.git] / lib / Plack / Session / State / Cookie.pm
CommitLineData
bd992981 1package Plack::Session::State::Cookie;
2use strict;
3use warnings;
4
5use parent 'Plack::Session::State';
6
ac4892f4 7use Plack::Util::Accessor qw[
8 path
9 domain
10 expires
11 secure
12];
bd992981 13
14sub expire_session_id {
15 my ($self, $id) = @_;
16 $self->SUPER::expire_session_id( $id );
17 $self->expires( 0 );
18}
19
20sub extract {
21 my ($self, $request) = @_;
22 $self->check_expired( ( $request->cookie( $self->session_key ) || return )->value );
23}
24
25sub finalize {
26 my ($self, $id, $response) = @_;
27 $response->cookies->{ $self->session_key } = +{
28 value => $id,
29 path => ($self->path || '/'),
05b5f99d 30 ( defined $self->domain ? ( domain => $self->domain ) : () ),
31 ( defined $self->expires ? ( expires => $self->expires ) : () ),
32 ( defined $self->secure ? ( secure => $self->secure ) : () ),
bd992981 33 };
05b5f99d 34
35 # clear the expires after
36 # finalization if the session
37 # has been expired - SL
38 $self->expires( undef )
39 if defined $self->expires
40 && $self->expires == 0
41 && $self->is_session_expired( $id );
bd992981 42}
43
fe1bfe7d 441;
ac4892f4 45
46__END__
47
48=pod
49
50=head1 NAME
51
52Plack::Session::State::Cookie - Basic cookie-based session state
53
54=head1 DESCRIPTION
55
56=head1 METHODS
57
58=over 4
59
60=item B<new ( %params )>
61
62=item B<path>
63
64=item B<domain>
65
66=item B<expires>
67
68=item B<secure>
69
70=back
71
72=over 4
73
74=item B<extract ( $request )>
75
76=item B<finalize ( $session_id, $response )>
77
78=back
79
80=over 4
81
82=item B<expire_session_id ( $id )>
83
84=back
85
86=head1 BUGS
87
88All complex software has bugs lurking in it, and this module is no
89exception. If you find a bug please either email me, or add the bug
90to cpan-RT.
91
92=head1 AUTHOR
93
94Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
95
96=head1 COPYRIGHT AND LICENSE
97
98Copyright 2009 Infinity Interactive, Inc.
99
100L<http://www.iinteractive.com>
101
102This library is free software; you can redistribute it and/or modify
103it under the same terms as Perl itself.
104
105=cut
106
107