1 package Catalyst::Plugin::Session::State::Cookie;
2 use base qw/Catalyst::Plugin::Session::State/;
14 $c->NEXT::setup_session(@_);
16 $c->config->{session}{cookie_name} ||= "session";
22 my $cookie_name = $c->config->{session}{cookie_name};
24 if ( my $sid = $c->sessionid ) {
25 my $cookie = $c->request->cookies->{$cookie_name};
26 if ( !$cookie or $cookie->value ne $sid ) {
27 $c->response->cookies->{$cookie_name} = {
29 expires => $c->session->{__expires},
31 if ( $c->config->{session}{cookie_domain} ) {
32 $c->response->cookies->{$cookie_name}->{domain} =
33 $c->config->{session}{cookie_domain};
35 $c->log->debug(qq/A cookie with the session id "$sid" was saved/)
40 return $c->NEXT::finalize(@_);
46 my $ret = $c->NEXT::prepare_cookies(@_);
48 my $cookie_name = $c->config->{session}{cookie_name};
50 if ( my $cookie = $c->request->cookies->{$cookie_name} ) {
51 my $sid = $cookie->value;
53 $c->log->debug(qq/Found sessionid "$sid" in cookie/) if $c->debug;
67 Catalyst::Plugin::Session::State::Cookie - A session ID
71 use Catalyst qw/Session Session::State::Cookie Session::Store::Foo/;
75 In order for L<Catalyst::Plugin::Session> to work the session ID needs to be
76 stored on the client, and the session data needs to be stored on the server.
78 This plugin stores the session ID on the client using the cookie mechanism.
80 =head1 EXTENDED METHODS
86 Will restore if an appropriate cookie is found.
90 Will set a cookie called C<session> if it doesn't exist or if it's value is not
91 the current session id.
95 Will set the C<cookie_name> parameter to it's default value if it isn't set.
105 The name of the cookie to store (defaults to C<session>).
109 The name of the domain to store in the cookie (defaults to current host)
115 L<Catalyst>, L<Catalyst::Plugin::Session>.
119 Sebastian Riedel E<lt>C<sri@cpan.org>E<gt>,
120 Marcus Ramberg E<lt>C<mramberg@cpan.org>E<gt>,
121 Andrew Ford E<lt>C<andrewf@cpan.org>E<gt>,
122 Yuval Kogman E<lt>C<nothingmuch@woobling.org>E<gt>
126 This program is free software, you can redistribute it and/or modify it
127 under the same terms as Perl itself.