pre-0.02 commit
[catagits/Web-Session.git] / lib / Plack / Session / State / Cookie.pm
CommitLineData
bd992981 1package Plack::Session::State::Cookie;
2use strict;
3use warnings;
4
de784fad 5our $VERSION = '0.02';
30cc0a71 6our $AUTHORITY = 'cpan:STEVAN';
7
bd992981 8use parent 'Plack::Session::State';
9
ac4892f4 10use Plack::Util::Accessor qw[
11 path
12 domain
13 expires
14 secure
15];
bd992981 16
17sub expire_session_id {
18 my ($self, $id) = @_;
19 $self->SUPER::expire_session_id( $id );
20 $self->expires( 0 );
21}
22
ae35574f 23sub get_session_id_from_request {
bd992981 24 my ($self, $request) = @_;
ae35574f 25 ( $request->cookie( $self->session_key ) || return )->value;
bd992981 26}
27
28sub finalize {
29 my ($self, $id, $response) = @_;
30 $response->cookies->{ $self->session_key } = +{
31 value => $id,
32 path => ($self->path || '/'),
05b5f99d 33 ( defined $self->domain ? ( domain => $self->domain ) : () ),
34 ( defined $self->expires ? ( expires => $self->expires ) : () ),
35 ( defined $self->secure ? ( secure => $self->secure ) : () ),
bd992981 36 };
05b5f99d 37
38 # clear the expires after
39 # finalization if the session
40 # has been expired - SL
41 $self->expires( undef )
42 if defined $self->expires
43 && $self->expires == 0
44 && $self->is_session_expired( $id );
bd992981 45}
46
fe1bfe7d 471;
ac4892f4 48
49__END__
50
51=pod
52
53=head1 NAME
54
55Plack::Session::State::Cookie - Basic cookie-based session state
56
3d92cf47 57=head1 SYNOPSIS
58
59 use Plack::Builder;
60 use Plack::Middleware::Session;
61
62 my $app = sub {
63 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
64 };
65
66 builder {
67 enable 'Session'; # Cookie is the default state
68 $app;
69 };
70
ac4892f4 71=head1 DESCRIPTION
72
43f34c01 73This is a subclass of L<Plack::Session::State> and implements it's
3d92cf47 74full interface. This is the default state used in
75L<Plack::Middleware::Session>.
43f34c01 76
ac4892f4 77=head1 METHODS
78
79=over 4
80
81=item B<new ( %params )>
82
3d92cf47 83The C<%params> can include I<path>, I<domain>, I<expires> and
84I<secure> options, as well as all the options accepted by
85L<Plack::Session::Store>.
86
ac4892f4 87=item B<path>
88
3d92cf47 89Path of the cookie, this defaults to "/";
90
ac4892f4 91=item B<domain>
92
3d92cf47 93Domain of the cookie, if nothing is supplied then it will not
94be included in the cookie.
95
ac4892f4 96=item B<expires>
97
3d92cf47 98Expiration time of the cookie, if nothing is supplied then it will
99not be included in the cookie.
100
ac4892f4 101=item B<secure>
102
3d92cf47 103Secure flag for the cookie, if nothing is supplied then it will not
104be included in the cookie.
105
ac4892f4 106=back
107
ac4892f4 108=head1 BUGS
109
110All complex software has bugs lurking in it, and this module is no
111exception. If you find a bug please either email me, or add the bug
112to cpan-RT.
113
114=head1 AUTHOR
115
116Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
117
118=head1 COPYRIGHT AND LICENSE
119
120Copyright 2009 Infinity Interactive, Inc.
121
122L<http://www.iinteractive.com>
123
124This library is free software; you can redistribute it and/or modify
125it under the same terms as Perl itself.
126
127=cut
128
129