Commit | Line | Data |
bd992981 |
1 | package Plack::Session::State::Cookie; |
2 | use strict; |
3 | use warnings; |
4 | |
5 | use parent 'Plack::Session::State'; |
6 | |
ac4892f4 |
7 | use Plack::Util::Accessor qw[ |
8 | path |
9 | domain |
10 | expires |
11 | secure |
12 | ]; |
bd992981 |
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 || '/'), |
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 |
44 | 1; |
ac4892f4 |
45 | |
46 | __END__ |
47 | |
48 | =pod |
49 | |
50 | =head1 NAME |
51 | |
52 | Plack::Session::State::Cookie - Basic cookie-based session state |
53 | |
3d92cf47 |
54 | =head1 SYNOPSIS |
55 | |
56 | use Plack::Builder; |
57 | use Plack::Middleware::Session; |
58 | |
59 | my $app = sub { |
60 | return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ]; |
61 | }; |
62 | |
63 | builder { |
64 | enable 'Session'; # Cookie is the default state |
65 | $app; |
66 | }; |
67 | |
ac4892f4 |
68 | =head1 DESCRIPTION |
69 | |
43f34c01 |
70 | This is a subclass of L<Plack::Session::State> and implements it's |
3d92cf47 |
71 | full interface. This is the default state used in |
72 | L<Plack::Middleware::Session>. |
43f34c01 |
73 | |
ac4892f4 |
74 | =head1 METHODS |
75 | |
76 | =over 4 |
77 | |
78 | =item B<new ( %params )> |
79 | |
3d92cf47 |
80 | The C<%params> can include I<path>, I<domain>, I<expires> and |
81 | I<secure> options, as well as all the options accepted by |
82 | L<Plack::Session::Store>. |
83 | |
ac4892f4 |
84 | =item B<path> |
85 | |
3d92cf47 |
86 | Path of the cookie, this defaults to "/"; |
87 | |
ac4892f4 |
88 | =item B<domain> |
89 | |
3d92cf47 |
90 | Domain of the cookie, if nothing is supplied then it will not |
91 | be included in the cookie. |
92 | |
ac4892f4 |
93 | =item B<expires> |
94 | |
3d92cf47 |
95 | Expiration time of the cookie, if nothing is supplied then it will |
96 | not be included in the cookie. |
97 | |
ac4892f4 |
98 | =item B<secure> |
99 | |
3d92cf47 |
100 | Secure flag for the cookie, if nothing is supplied then it will not |
101 | be included in the cookie. |
102 | |
ac4892f4 |
103 | =back |
104 | |
ac4892f4 |
105 | =head1 BUGS |
106 | |
107 | All complex software has bugs lurking in it, and this module is no |
108 | exception. If you find a bug please either email me, or add the bug |
109 | to cpan-RT. |
110 | |
111 | =head1 AUTHOR |
112 | |
113 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
114 | |
115 | =head1 COPYRIGHT AND LICENSE |
116 | |
117 | Copyright 2009 Infinity Interactive, Inc. |
118 | |
119 | L<http://www.iinteractive.com> |
120 | |
121 | This library is free software; you can redistribute it and/or modify |
122 | it under the same terms as Perl itself. |
123 | |
124 | =cut |
125 | |
126 | |