update example to use Plack::Request->session, add docs about where we store session
Stevan Little [Tue, 15 Dec 2009 18:53:28 +0000 (13:53 -0500)]
Changes
examples/app.psgi
lib/Plack/Middleware/Session.pm

diff --git a/Changes b/Changes
index 6d206ed..cacc17f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
 Revision history for Perl extension Plack::Middleware::Session
 
-0.01
+0.01 Tues. Dec. 15, 2009
     - original version
\ No newline at end of file
index 8f2b548..cb67b09 100644 (file)
@@ -13,7 +13,7 @@ my $app = Plack::Middleware::Session->wrap(
 
         return [ 404, [], [] ] if $r->path_info =~ /favicon.ico/;
 
-        my $session = $env->{'plack.session'};
+        my $session = $r->session;
 
         my $id      = $session->id;
         my $counter = $session->get('counter') || 0;
index 03f8798..dab15cb 100644 (file)
@@ -74,7 +74,12 @@ Plack::Middleware::Session - Middleware for session management
   use Plack::Builder;
 
   my $app = sub {
-      return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
+      my $env = shift;
+      return [
+          200,
+          [ 'Content-Type' => 'text/plain' ],
+          [ 'Hello, your Session ID is ' . $env->{'plack.session'}->id ]
+      ];
   };
 
   builder {
@@ -96,6 +101,12 @@ default it will use cookies to keep session state and store data in
 memory. This distribution also comes with other state and store
 solutions. See perldoc for these backends how to use them.
 
+It should be noted that we store the current session in the
+C<plack.session> key inside the C<$env> where you can access it
+as needed. Additionally, as of version 0.09, you can call the
+C<session> method of a L<Plack::Request> instance to fetch
+whatever is stored in C<plack.session>.
+
 =head2 State
 
 =over 4