package Catalyst::Plugin::Session::State::Stash;
-use base qw/Catalyst::Plugin::Session::State Class::Accessor::Fast/;
-
-use strict;
-use warnings;
+use Moose;
+use 5.008;
use MRO::Compat;
+use namespace::autoclean;
+
+extends 'Catalyst::Plugin::Session::State';
-use Data::Dumper qw/Dumper/;
-our $VERSION = "0.10";
+our $VERSION = "0.12";
-BEGIN { __PACKAGE__->mk_accessors(qw/_deleted_session_id _prepared/) }
+has _deleted_session_id => ( is => 'rw' );
+has _prepared => ( is => 'rw' );
sub _stash_key_components {
my ($c) = @_;
- return ($c->config->{session}->{stash_delim}) ?
- split $c->config->{session}->{stash_delim}, $c->config->{session}->{stash_key} :
- $c->config->{session}->{stash_key};
+ my $config = $c->_session_plugin_config;
+ return ($config->{stash_delim}) ?
+ split $config->{stash_delim}, $config->{stash_key} :
+ $config->{stash_key};
}
sub _get_session {
sub _set_session {
my ( $c,$key,$value) = @_;
-
$c->_get_session->{$key} = $value;
}
sub setup_session {
my $c = shift;
-
- $c->config->{session}->{stash_key}
- ||= '_session';
+ $c->_session_plugin_config->{stash_key} ||= '_session';
}
sub prepare_action {
sub set_session_expires {
my ( $c, $expires ) = @_;
-
$c->_set_session(expires => time() + $expires);
$c->maybe::next::method($expires)
}
and key of '123/456' will store it as $c->stash->{123}->{456}
=item expires
-
+
How long the session should last in seconds.
=back
For example, you could stick this in MyApp.pm:
- __PACKAGE__->config( session => {
+ __PACKAGE__->config( 'Plugin::Session' => {
stash_key => 'session_id',
});
Manual work may be involved to make better use of this.
If you are writing a stateful web service with
-L<Catalyst::Plugin::Server::XMLRPC>, you will probably only have to deal with
+L<Catalyst::Plugin::Server::XMLRPC>, you will probably only have to deal with
loading, as when saving, the ID will already be on the stash.
=head1 SEE ALSO
=cut
-1;