Commit | Line | Data |
---|---|---|
1a776a0c | 1 | package Catalyst::Plugin::Session::State::Cookie; |
2 | use base qw/Catalyst::Plugin::Session::State/; | |
bf2bce67 | 3 | |
4 | use strict; | |
1a776a0c | 5 | use warnings; |
bf2bce67 | 6 | |
1a776a0c | 7 | use NEXT; |
bf2bce67 | 8 | |
9 | sub finalize { | |
b2f8df5e | 10 | my $c = shift; |
1a776a0c | 11 | |
bf2bce67 | 12 | if ( my $sid = $c->sessionid ) { |
1a776a0c | 13 | my $cookie = $c->request->cookies->{session}; |
14 | if ( !$cookie or $cookie->value ne $sid ) { | |
15 | $c->response->cookies->{session} = { value => $sid }; | |
16 | $c->log->debug(qq/A cookie with the session id "$sid" was saved/) | |
17 | if $c->debug; | |
58c05d1a | 18 | } |
bf2bce67 | 19 | } |
1a776a0c | 20 | |
bf2bce67 | 21 | return $c->NEXT::finalize(@_); |
22 | } | |
23 | ||
1a776a0c | 24 | sub prepare_cookies { |
bf2bce67 | 25 | my $c = shift; |
1a776a0c | 26 | |
bf2bce67 | 27 | if ( my $cookie = $c->request->cookies->{session} ) { |
28 | my $sid = $cookie->value; | |
29 | $c->sessionid($sid); | |
30 | $c->log->debug(qq/Found sessionid "$sid" in cookie/) if $c->debug; | |
31 | } | |
bf2bce67 | 32 | |
1a776a0c | 33 | $c->NEXT::prepare_cookies(@_); |
bf2bce67 | 34 | } |
35 | ||
1a776a0c | 36 | __PACKAGE__ |
57dbf608 | 37 | |
1a776a0c | 38 | __END__ |
bf2bce67 | 39 | |
1a776a0c | 40 | =pod |
b2f8df5e | 41 | |
1a776a0c | 42 | =head1 NAME |
bf2bce67 | 43 | |
1a776a0c | 44 | Catalyst::Plugin::Session::State::Cookie - A session ID |
bf2bce67 | 45 | |
1a776a0c | 46 | =head1 SYNOPSIS |
bf2bce67 | 47 | |
1a776a0c | 48 | use Catalyst qw/Session Session::State::Cookie Session::Store::Foo/; |
bf2bce67 | 49 | |
1a776a0c | 50 | =head1 DESCRIPTION |
bf2bce67 | 51 | |
1a776a0c | 52 | In order for L<Catalyst::Plugin::Session> to work the session ID needs to be |
53 | stored on the client, and the session data needs to be stored on the server. | |
bf2bce67 | 54 | |
1a776a0c | 55 | This plugin stores the session ID on the client using the cookie mechanism. |
57dbf608 | 56 | |
1a776a0c | 57 | =head1 EXTENDED METHODS |
58c05d1a | 58 | |
57dbf608 | 59 | =over 4 |
60 | ||
1a776a0c | 61 | =item prepare_cookies |
57dbf608 | 62 | |
1a776a0c | 63 | Will restore if an appropriate cookie is found. |
58c05d1a | 64 | |
1a776a0c | 65 | =item finalize |
58c05d1a | 66 | |
1a776a0c | 67 | Will set a cookie called C<session> if it doesn't exist or if it's value is not the current session id. |
58c05d1a | 68 | |
57dbf608 | 69 | =back |
58c05d1a | 70 | |
bf2bce67 | 71 | =head1 SEE ALSO |
72 | ||
1a776a0c | 73 | L<Catalyst>, L<Catalyst::Plugin::Session>. |
bf2bce67 | 74 | |
75 | =head1 AUTHOR | |
76 | ||
57dbf608 | 77 | Sebastian Riedel E<lt>C<sri@cpan.org>E<gt>, |
78 | Marcus Ramberg E<lt>C<mramberg@cpan.org>E<gt>, | |
1a776a0c | 79 | Andrew Ford E<lt>C<andrewf@cpan.org>E<gt>, |
80 | Yuval Kogman E<lt>C<nothingmuch@woobling.org>E<gt> | |
bf2bce67 | 81 | |
82 | =head1 COPYRIGHT | |
83 | ||
bfeb5ca0 | 84 | This program is free software, you can redistribute it and/or modify it |
85 | under the same terms as Perl itself. | |
bf2bce67 | 86 | |
87 | =cut | |
88 | ||
89 | 1; |