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)->cookie( $self->session_key ) || return )->value;
24 sub expire_session_id {
25 my ($self, $id, $res, $options) = @_;
26 $self->_set_cookie($id, $res, expires => 0);
30 my ($self, $id, $res, $options) = @_;
31 $self->_set_cookie($id, $res, (defined $self->expires ? (expires => $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, if nothing is supplied then it will
103 not be included in the cookie.
107 Secure flag for the cookie, if nothing is supplied then it will not
108 be included in the cookie.
114 All complex software has bugs lurking in it, and this module is no
115 exception. If you find a bug please either email me, or add the bug
120 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
122 =head1 COPYRIGHT AND LICENSE
124 Copyright 2009, 2010 Infinity Interactive, Inc.
126 L<http://www.iinteractive.com>
128 This library is free software; you can redistribute it and/or modify
129 it under the same terms as Perl itself.