summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-22 17:44:42 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-22 17:44:42 +0200
commit38cea1b916dd3c615f81813f9d04e2dde3e63410 (patch)
tree555fa5bd27eff8b571455060972cfe0dfd9ed747
parentuse P::M::Session as backend for dancer's sessions (diff)
downloaddancer-session-psgi-38cea1b916dd3c615f81813f9d04e2dde3e63410.tar.gz
POD and better use of psgix
-rw-r--r--lib/Dancer/Session/PSGI.pm54
1 files changed, 49 insertions, 5 deletions
diff --git a/lib/Dancer/Session/PSGI.pm b/lib/Dancer/Session/PSGI.pm
index c530961..f82cb0d 100644
--- a/lib/Dancer/Session/PSGI.pm
+++ b/lib/Dancer/Session/PSGI.pm
@@ -7,21 +7,31 @@ our $VERSION = '0.01';
 use Dancer::SharedData;
 use base 'Dancer::Session::Abstract';
 
+# session_name can't be set in config for this module
+sub session_name {
+    "plack_session";
+}
+
+sub create {
+    return Dancer::Session::PSGI->new();
+}
+
 sub retrieve {
     my ($class, $id) = @_;
-    my $req = Plack::Request->new(Dancer::SharedData->request->{env});
-    my $session = $req->session();
+    my $session = Dancer::SharedData->request->{env}->{'psgix.session'};
     return Dancer::Session::PSGI->new(%$session);
 }
 
 sub flush {
     my $self = shift;
-    my $req = Plack::Request->new(Dancer::SharedData->request->{env});
-    my $session = $req->session();
+    my $session = Dancer::SharedData->request->{env}->{'psgix.session'};
     map {$session->{$_} = $self->{$_}} keys %$self;
     return $self;
 }
 
+sub destroy {
+}
+
 1;
 __END__
 
@@ -31,7 +41,41 @@ Dancer::Session::PSGI - Let Plack::Middleware::Session handle session
 
 =head1 SYNOPSIS
 
-    setting session => 'PSGI'
+A basic psgi application
+
+    use strict; use warnings;
+    use Plack::Builder;
+
+    my $app = sub {
+        my $session = (shift)->{'psgix.session'};
+        return [
+            200,
+            [ 'Content-Type' => 'text/plain' ],
+            [ "Hello, you've been here for ", $session->{counter}++, "th time!" ],
+        ];
+    };
+
+    builder { enable 'Session', store => 'File'; $app; };
+
+In your app.psgi:
+
+    builder {
+        enable "Session", store => "File";
+        sub { my $env = shift; my $request = Dancer::Request->new($env); Dancer->dance($request);};
+    };
+
+And a simple Dancer application:
+
+   package session;
+   use Dancer ':syntax';
+
+    get '/' => sub {
+        my $count = session("counter");
+        session "counter" => ++$count;
+        template 'index', {count => $count};
+    };
+
+Now, your two applications can share the same session informations.
 
 =head1 DESCRIPTION