preliminary docs added, improved support for subclassing and sid_generator callback...
[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         ( $self->domain  ? ( domain  => $self->domain  ) : () ),
31         ( $self->expires ? ( expires => $self->expires ) : () ),
32         ( $self->secure  ? ( secure  => $self->secure  ) : () ),
33     };
34 }
35
36 1;
37
38 __END__
39
40 =pod
41
42 =head1 NAME
43
44 Plack::Session::State::Cookie - Basic cookie-based session state
45
46 =head1 DESCRIPTION
47
48 =head1 METHODS
49
50 =over 4
51
52 =item B<new ( %params )>
53
54 =item B<path>
55
56 =item B<domain>
57
58 =item B<expires>
59
60 =item B<secure>
61
62 =back
63
64 =over 4
65
66 =item B<extract ( $request )>
67
68 =item B<finalize ( $session_id, $response )>
69
70 =back
71
72 =over 4
73
74 =item B<expire_session_id ( $id )>
75
76 =back
77
78 =head1 BUGS
79
80 All complex software has bugs lurking in it, and this module is no
81 exception. If you find a bug please either email me, or add the bug
82 to cpan-RT.
83
84 =head1 AUTHOR
85
86 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
87
88 =head1 COPYRIGHT AND LICENSE
89
90 Copyright 2009 Infinity Interactive, Inc.
91
92 L<http://www.iinteractive.com>
93
94 This library is free software; you can redistribute it and/or modify
95 it under the same terms as Perl itself.
96
97 =cut
98
99