1 package Plack::Session::State::Cookie;
6 our $AUTHORITY = 'cpan:STEVAN';
8 use parent 'Plack::Session::State';
12 use Plack::Util::Accessor qw[
20 my ($self, $env) = @_;
21 Plack::Request->new($env)->cookies->{$self->session_key};
24 sub expire_session_id {
25 my ($self, $id, $res, $options) = @_;
26 $self->_set_cookie($id, $res, expires => time);
30 my ($self, $id, $res, $options) = @_;
31 $self->_set_cookie($id, $res, (defined $self->expires ? (expires => time + $self->expires) : ()));
35 my($self, $id, $res, %options) = @_;
37 # TODO: Do not use Plack::Response
38 my $response = Plack::Response->new($res);
39 $response->cookies->{ $self->session_key } = +{
41 path => ($self->path || '/'),
42 ( defined $self->domain ? ( domain => $self->domain ) : () ),
43 ( defined $self->secure ? ( secure => $self->secure ) : () ),
47 my $final_r = $response->finalize;
48 $res->[1] = $final_r->[1]; # headers
59 Plack::Session::State::Cookie - Basic cookie-based session state
64 use Plack::Middleware::Session;
67 return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
71 enable 'Session'; # Cookie is the default state
77 This is a subclass of L<Plack::Session::State> and implements it's
78 full interface. This is the default state used in
79 L<Plack::Middleware::Session>.
85 =item B<new ( %params )>
87 The C<%params> can include I<path>, I<domain>, I<expires> and
88 I<secure> options, as well as all the options accepted by
89 L<Plack::Session::Store>.
93 Path of the cookie, this defaults to "/";
97 Domain of the cookie, if nothing is supplied then it will not
98 be included in the cookie.
102 Expiration time of the cookie in seconds, if nothing is supplied then
103 it will not be included in the cookie, which means the session expires
108 Secure flag for the cookie, if nothing is supplied then it will not
109 be included in the cookie.
115 All complex software has bugs lurking in it, and this module is no
116 exception. If you find a bug please either email me, or add the bug
121 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
123 =head1 COPYRIGHT AND LICENSE
125 Copyright 2009, 2010 Infinity Interactive, Inc.
127 L<http://www.iinteractive.com>
129 This library is free software; you can redistribute it and/or modify
130 it under the same terms as Perl itself.