Permalink
Browse files

Using Plack sessions in WebNano - an example

  • Loading branch information...
1 parent 5838caa commit 242517c0d6a491357b866718c01ae01727d8bebd Zbigniew Lukasiak committed Jun 20, 2010
View
11 examples/DvdDatabase/app.psgi
@@ -1,5 +1,14 @@
+use warnings;
+use strict;
+
use DvdDatabase;
+use Plack::Builder;
+
+
my $app = DvdDatabase->new();
-$app->psgi_callback;
+builder {
+ enable 'Session';
+ $app->psgi_callback;
+}
View
2 examples/DvdDatabase/dist.ini
@@ -7,4 +7,6 @@ copyright_year = 2010
[@Basic]
[AutoVersion]
[AutoPrereq]
+[Prereq]
+Plack::Middleware::Session = 0
[TestRelease]
View
6 examples/DvdDatabase/lib/DvdDatabase/Controller.pm
@@ -12,5 +12,11 @@ sub index_action {
return $res;
}
+sub session_check_action {
+ my $self = shift;
+ my $session = $self->env->{'psgix.session'};
+ return "Hello, you've been here for ". ( 1 + $session->{counter}++ ). "th time!";
+}
+
1;
View
10 examples/DvdDatabase/t/crudapp.t
@@ -3,11 +3,14 @@ use Plack::Test;
use HTTP::Request::Common;
use DvdDatabase;
use File::Copy;
+use Plack::Middleware::Session;
+use Test::WWW::Mechanize::PSGI;
copy('t/data/dvdzbr.db','t/tmp/dvdzbr.db') or die "Copy failed: $!";
+my $app = Plack::Middleware::Session->wrap( DvdDatabase->new()->psgi_callback );
test_psgi(
- app => DvdDatabase->new()->psgi_callback,
+ app => $app,
client => sub {
my $cb = shift;
my $res;
@@ -24,4 +27,9 @@ test_psgi(
}
);
+my $mech = Test::WWW::Mechanize::PSGI->new( app => $app );
+$mech->get_ok( '/session_check' );
+$mech->content_contains( "Hello, you've been here for 1th time!" );
+$mech->get_ok( '/session_check' );
+$mech->content_contains( "Hello, you've been here for 2th time!" );
done_testing();

0 comments on commit 242517c

Please sign in to comment.