docs, docs and more docs
[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[
8     path
9     domain
10     expires
11     secure
12 ];
13
14 sub expire_session_id {
15     my ($self, $id) = @_;
16     $self->SUPER::expire_session_id( $id );
17     $self->expires( 0 );
18 }
19
20 sub extract {
21     my ($self, $request) = @_;
22     $self->check_expired( ( $request->cookie( $self->session_key ) || return )->value );
23 }
24
25 sub finalize {
26     my ($self, $id, $response) = @_;
27     $response->cookies->{ $self->session_key } = +{
28         value => $id,
29         path  => ($self->path || '/'),
30         ( defined $self->domain  ? ( domain  => $self->domain  ) : () ),
31         ( defined $self->expires ? ( expires => $self->expires ) : () ),
32         ( defined $self->secure  ? ( secure  => $self->secure  ) : () ),
33     };
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 );
42 }
43
44 1;
45
46 __END__
47
48 =pod
49
50 =head1 NAME
51
52 Plack::Session::State::Cookie - Basic cookie-based session state
53
54 =head1 DESCRIPTION
55
56 This is a subclass of L<Plack::Session::State> and implements it's
57 full interface.
58
59 =head1 METHODS
60
61 =over 4
62
63 =item B<new ( %params )>
64
65 =item B<path>
66
67 =item B<domain>
68
69 =item B<expires>
70
71 =item B<secure>
72
73 =back
74
75 =head1 BUGS
76
77 All complex software has bugs lurking in it, and this module is no
78 exception. If you find a bug please either email me, or add the bug
79 to cpan-RT.
80
81 =head1 AUTHOR
82
83 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
84
85 =head1 COPYRIGHT AND LICENSE
86
87 Copyright 2009 Infinity Interactive, Inc.
88
89 L<http://www.iinteractive.com>
90
91 This library is free software; you can redistribute it and/or modify
92 it under the same terms as Perl itself.
93
94 =cut
95
96