Amon2-Plugin-Web-HTTPSession
view release on metacpan or search on metacpan
t/003_session.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Requires 'Test::WWW::Mechanize::PSGI', 'HTTP::Session', 'HTML::StickyQuery', 'Amon2::Plugin::Web::MobileCharset';
use Plack::Middleware::Lint;
use Text::Xslate;
{
package MyApp;
use parent qw/Amon2/;
sub load_config {
+{ 'HTTP::Session::State::URI' => { session_id_name => 'amon_sid', }, };
}
package MyApp::Web;
use parent -norequire, qw/MyApp/;
use parent qw/Amon2::Web/;
__PACKAGE__->load_plugin('Web::MobileCharset');
__PACKAGE__->load_plugin('Web::MobileAgent');
my $xslate = Text::Xslate->new(
syntax => 'TTerse',
function => {
c => sub { Amon2->context },
},
path => {
'step2' => <<'...',
<!doctype html>
<html><body>ããã[% c().session().get('foo') %]<form method="post" action="step3"><input type="submit" /></form></body></html>
...
'step3' => <<'...',
<!doctype html>
<html><body>ããã[% c().session().get('foo') %]</body></html>
...
},
);
sub create_view { $xslate }
sub dispatch {
my $c = shift;
if ($c->request->path_info eq '/') {
$c->session->set(foo => 'bar');
::ok(!$c->{"__PACKAGE__"});
return $c->redirect('/step2');
} elsif ($c->request->path_info eq '/step2') {
return $c->render('step2');
} elsif ($c->request->path_info eq '/step3') {
return $c->render('step3');
} else {
return $c->create_response(404, [], []);
}
}
__PACKAGE__->load_plugins(
'Web::HTTPSession' => {
state => 'URI',
store => 'OnMemory',
},
);
}
( run in 1.315 second using v1.01-cache-2.11-cpan-39bf76dae61 )