my $c = shift;
if ( my $sid = $c->sessionid ) {
- $c->log->debug(qq/Found session "$sid"/) if $c->debug;
-
my $s = $c->{session} ||= $c->get_session_data($sid);
if ( !$s or $s->{__expires} < time ) {
$c->log->debug("Deleting session $sid (expired)") if $c->debug;
$c->delete_session("session expired");
}
-
- elsif ( $c->config->{session}{verify_address}
+ elsif ($c->config->{session}{verify_address}
&& $c->{session}{__address}
&& $c->{session}{__address} ne $c->request->address )
{
);
$c->delete_session("address mismatch");
}
+ else {
+ $c->log->debug(qq/Restored session "$sid"/) if $c->debug;
+ }
}
$c->NEXT::prepare_action(@_);
unless ($usable) {
foreach my $alg (qw/SHA-1 MD5 SHA-256/) {
eval {
- my $obj = Digest->new($alg);
- $usable = $alg;
- return $obj;
- }
+ my $obj = Digest->new($alg);
+ $usable = $alg;
+ return $obj;
+ };
}
$usable
or Catalyst::Exception->throw(
=head1 SYNOPSIS
- use Catalyst qw/Session Session::Store::FastMmap Session::State::Cookie/;
+ # To get sessions to "just work", all you need to do is use these plugins:
+
+ use Catalyst qw/
+ Session
+ Session::Store::FastMmap
+ Session::State::Cookie
+ /;
+
+ # you can replace Store::FastMmap with Store::File - both have sensible
+ # default configurations (see their docs for details)
+
+ # more complicated backends are available for other scenarios (DBI storage,
+ # etc)
+
+
+ # after you've loaded the plugins you can save session data
+ # For example, if you are writing a shopping cart, it could be implemented
+ # like this:
sub add_item : Local {
my ( $self, $c ) = @_;
my $item_id = $c->req->param("item");
- # $c->session is stored across requests, so
- # other actions will see these values
+ # $c->session is a hash ref, a bit like $c->stash
+ # the difference is that it' preserved across requests
push @{ $c->session->{items} }, $item_id;
# values in $c->session are restored
$c->stash->{items_to_display} =
- [ map { MyModel->retrieve($_) } @{ $c->session->{items} } ];
+ [ map { MyModel->retrieve($_) } @{ $c->session->{items} } ];
$c->forward("MyView");
}
This plugin links the two pieces together.
+=head1 RECCOMENDED BACKENDS
+
+=over 4
+
+=item Session::State::Cookie
+
+The only really sane way to do state is using cookies.
+
+=item Session::Store::File
+
+A portable backend, based on Cache::File.
+
+=item Session::Store::FastMmap
+
+A fast and flexible backend, based on Cache::FastMmap.
+
+=back
+
=head1 METHODS
=over 4
=back
+=back
+
+=item INTERNAL METHODS
+
+=over 4
+
=item setup
This method is extended to also make calls to
this box is checked it should delete the C<__address> sepcial key from the
session hash when the hash is first created.
+=head1 AUTHORS
+
+Andy Grundman
+Christian Hansen
+Yuval Kogman, C<nothingmuch@woobling.org>
+Sebastian Riedel
+
+=head1 COPYRIGHT & LICNESE
+
+ Copyright (c) 2005 the aforementioned authors. All rights
+ reserved. This program is free software; you can redistribute
+ it and/or modify it under the same terms as Perl itself.
+
=cut