1 package Catalyst::Plugin::Session::State::Stash;
2 use base qw/Catalyst::Plugin::Session::State Class::Accessor::Fast/;
10 BEGIN { __PACKAGE__->mk_accessors(qw/_deleted_session_id _prepared/) }
12 sub _session_stash_key {
15 $c->config->{session}->{stash_key};
21 $c->stash->{$c->_session_stash_key};
25 my ( $c,$key,$value) = @_;
27 $c->stash->{$c->_session_stash_key}->{$key} = $value;
33 $c->config->{session}->{stash_key}
39 my $id = $c->get_session_id;
44 $c->maybe::next::method( @_ );
49 if(!$c->_deleted_session_id and my $session = $c->_get_session) {
50 my $sid = $session->{id};
53 $c->maybe::next::method(@_);
58 $c->_set_session(id => $sid);
59 $c->maybe::next::method($sid);
62 sub get_session_expires {
64 my $session = $c->_get_session;
65 defined $session->{expires} ? $session->{expires} : undef;
68 sub set_session_expires {
69 my ( $c, $expires ) = @_;
71 $c->_set_session(expires => time() + $expires);
72 $c->maybe::next::method($expires)
75 sub delete_session_id {
77 $c->_deleted_session_id(1);
78 undef $c->{stash}->{$c->_session_stash_key};
79 $c->maybe::next::method($sid);
90 Catalyst::Plugin::Session::State::Stash - Maintain session IDs using the stash
94 use Catalyst qw/Session Session::State::Stash Session::Store::Foo/;
98 An alternative state storage plugin that allows you some more flexibility in
99 dealing with session storage. This plugin loads and saves the session ID from
106 =item delete_session_id
108 Deletes the session. Unfortunately I've been unable to squash a bug that will
109 stop you from opening a new session in the same execution, however.
114 Gets the current session id.
118 Sets the session id to the C<shift>.
120 =item get_session_expires
122 Gets when the current session expires.
124 =item set_session_expires
126 Sets how many seconds from now the session should expire.
130 =head1 EXTENDED METHODS
136 Loads the id off the stash.
140 Defaults the C<stash_key> parameter to C<_session>.
150 The name of the hash key to use. Defaults to C<_session>.
154 How long the session should last in seconds.
158 For example, you could stick this in MyApp.pm:
160 __PACKAGE__->config( session => {
161 stash_key => 'session_id',
166 You can't delete a session then create a new one. If this is important to you,
167 patches welcome. It is not important to me and fixing this for completeness
168 is pretty low on my list of priorities.
172 Manual work may be involved to make better use of this.
174 If you are writing a stateful web service with
175 L<Catalyst::Plugin::Server::XMLRPC>, you will probably only have to deal with
176 loading, as when saving, the ID will already be on the stash.
180 L<Catalyst>, L<Catalyst::Plugin::Session>, L<Catalyst::Plugin::Session::State>,
181 L<Catalyst::Plugin::Session::State::Cookie> (what you probably want).
185 James Laver E<lt>perl -e 'printf qw/%s@%s.com cpan jameslaver/'E<gt>
189 This module is derived from L<Catalyst::Plugin::Session::State::Cookie> code.
191 Thanks to anyone who wrote code for that.
195 This program is free software, you can redistribute it and/or modify it
196 under the same terms as Perl itself.