Revision history for Perl extension Catalyst::Plugin::Session
+0.34 2012-03-30
+ - Fixed up t/live_verify_address.t per https://rt.cpan.org/Ticket/Display.html?id=71142
+
+0.33 2012-03-08
+ - Note that flash is deprecated / not recommended due to it's
+ inherent races. Point out Catalyst::Plugin::StatusMessage instead
+
0.32 2011-06-08
- Fix handling with enables verify_address and add related test
+\bMYMETA.yml\b
+
# Avoid version control files.
\bRCS\b
\bCVS\b
test_requires 'Test::Deep';
test_requires 'Test::Exception';
-
-resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Plugin-Session/0.00/trunk/';
+test_requires 'Test::WWW::Mechanize::PSGI';
+test_requires 'Plack::Middleware::ForceEnv';
+resources repository => 'git://git.shadowcat.co.uk/catagits/Catalyst-Plugin-Session.git';
WriteAll;
use namespace::clean -except => 'meta';
-our $VERSION = '0.32';
+our $VERSION = '0.34';
$VERSION = eval $VERSION;
my @session_data_accessors; # used in delete_session
sub finalize_headers {
my $c = shift;
- # fix cookie before we send headers
- $c->_save_session_expires;
+ # Force extension of session_expires before finalizing headers, so a possible cookie will be
+ # up to date. First call to session_expires will extend the expiry, subsequent calls will
+ # just return the previously extended value.
+ $c->session_expires;
return $c->maybe::next::method(@_);
}
$c->maybe::next::method(@_);
+ $c->_save_session_expires;
$c->_save_session_id;
$c->_save_session;
$c->_save_flash;
all the keys which haven't changed since the flash data was loaded at the end
of every request.
+Note that use of the flash is an easy way to get data across requests, but
+it's also strongly disrecommended, due it it being inherently plagued with
+race conditions. This means that it's unlikely to work well if your
+users have multiple tabs open at once, or if your site does a lot of AJAX
+requests.
+
+L<Catalyst::Plugin::StatusMessage> is the recommended alternative solution,
+as this doesn't suffer from these issues.
+
sub moose : Local {
my ( $self, $c ) = @_;
For example:
- __PACKAGE__->config('Plugin::Session' => { expires => 10000000000 }); # "forever"
+ __PACKAGE__->config('Plugin::Session' => { expires => 10000000000 }); # "forever"
(NB If this number is too large, Y2K38 breakage could result.)
# later
And countless other contributers from #catalyst. Thanks guys!
+=head1 Contributors
+
+Devin Austin (dhoss) <dhoss@cpan.org>
+
=head1 COPYRIGHT & LICENSE
Copyright (c) 2005 the aforementioned authors. All rights
@{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
- { __PACKAGE__->setup; }; # INSANE HACK
+ { __PACKAGE__->setup; }; # Extra block here is an INSANE HACK to get inlined constructor
+ # (i.e. to make B::Hooks::EndOfScope fire)
}
{
@{ __PACKAGE__->config->{'Plugin::Session'} }{ keys %$cfg } = values %$cfg;
- { __PACKAGE__->setup; }; # INSANE HACK
+ { __PACKAGE__->setup; }; # INSANE HACK (the block - as above)
}
use Test::More;
use warnings;
use Test::More;
-
BEGIN {
eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
or plan skip_all =>
"Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
eval {
- require Test::WWW::Mechanize::Catalyst;
- Test::WWW::Mechanize::Catalyst->VERSION(0.51);
+ require Test::WWW::Mechanize::PSGI;
+ #Test::WWW::Mechanize::Catalyst->VERSION(0.51);
}
or plan skip_all =>
- 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
+ 'Test::WWW::Mechanize::PSGI is required for this test';
plan tests => 12;
}
use lib "t/lib";
-use Test::WWW::Mechanize::Catalyst "SessionTestApp";
+use Test::WWW::Mechanize::PSGI;
+use SessionTestApp;
+my $ua = Test::WWW::Mechanize::PSGI->new(
+ app => SessionTestApp->psgi_app(@_),
+ cookie_jar => {}
+);
# Test without delete __address
local $ENV{REMOTE_ADDR} = "192.168.1.1";
-my $ua = Test::WWW::Mechanize::Catalyst->new( {} );
$ua->get_ok( "http://localhost/login" );
$ua->content_contains('logged in');
$ua->content_contains('session variable set');
-# Change Client
-local $ENV{REMOTE_ADDR} = "192.168.1.2";
-
-$ua->get_ok( "http://localhost/get_session_variable/logged");
-$ua->content_contains('VAR_logged=n.a.');
+# Change Client
+#local $ENV{REMOTE_ADDR} = "192.168.1.2";
+use Plack::Builder;
+my $app = SessionTestApp->psgi_app(@_);
+builder {
+ enable 'ForceEnv' => REMOTE_ADDR => "192.168.1.2";
+ $app;
+};
+my $ua2 = Test::WWW::Mechanize::PSGI->new(
+ app => $app,
+ cookie_jar => {}
+);
+$ua2->get_ok( "http://localhost/get_session_variable/logged");
+$ua2->content_contains('VAR_logged=n.a.');
# Inital Client
local $ENV{REMOTE_ADDR} = "192.168.1.1";
$ua->get_ok( "http://localhost/set_session_variable/logged/in" );
$ua->content_contains('session variable set');
-# Change Client
+# Change Client
local $ENV{REMOTE_ADDR} = "192.168.1.2";
$ua->get_ok( "http://localhost/get_session_variable/logged" );