remove session_class and psgix.session per discussion on IRC :)
Tatsuhiko Miyagawa [Mon, 11 Jan 2010 11:12:18 +0000 (03:12 -0800)]
Plack::Session as a library goes to where Plack::Request goes.

lib/Plack/Middleware/Session.pm
lib/Plack/Middleware/Session/Cookie.pm
lib/Plack/Session.pm
t/010_middleware.t
t/lib/TestSession.pm

index 1a325f3..9eaed64 100644 (file)
@@ -13,7 +13,6 @@ use parent 'Plack::Middleware';
 use Plack::Util::Accessor qw(
     state
     store
-    session_class
 );
 
 sub prepare_app {
@@ -22,8 +21,6 @@ sub prepare_app {
     $self->state( 'Cookie' ) unless $self->state;
     $self->state( $self->inflate_backend('Plack::Session::State', $self->state) );
     $self->store( $self->inflate_backend('Plack::Session::Store', $self->store) );
-
-    Plack::Util::load_class($self->session_class) if $self->session_class;
 }
 
 sub inflate_backend {
@@ -52,10 +49,6 @@ sub call {
 
     $env->{'psgix.session.options'} = { id => $id };
 
-    if ($self->session_class) {
-        $env->{'plack.session'} = $self->session_class->new($env);
-    }
-
     my $res = $self->app->($env);
     $self->response_cb($res, sub { $self->finalize($env, $_[0]) });
 }
@@ -161,9 +154,6 @@ access it as needed.
 B<NOTE:> As of version 0.04 the session is stored in C<psgix.session>
 instead of C<plack.session>.
 
-Also, if you set I<session_class> option (see below), we create a
-session object out of the hash reference in C<plack.session>.
-
 =head2 State
 
 =over 4
@@ -230,13 +220,6 @@ is only suitable for development (or single process servers). For a
 more robust solution see L<Plack::Session::Store::File> or
 L<Plack::Session::Store::Cache>.
 
-=item I<session_class>
-
-This can be used to create an actual session object in
-C<plack.session> environment. Defaults to none, which means the
-session object is not created but you can set C<Plack::Session> to
-create an object for you.
-
 =back
 
 =head1 BUGS
index 5e8e228..c185d3a 100644 (file)
@@ -15,7 +15,6 @@ use Plack::Session::State::Cookie;
 sub prepare_app {
     my $self = shift;
 
-    Plack::Util::load_class($self->session_class) if $self->session_class;
     $self->session_key("plack_session") unless $self->session_key;
 
     $self->state( Plack::Session::State::Cookie->new );
index e6a1c91..6749c08 100644 (file)
@@ -9,8 +9,6 @@ use Plack::Util::Accessor qw( session options );
 
 sub new {
     my ($class, $env) = @_;
-    # NOTE: when you make a subclass, be sure to NEVER save $env in
-    # your hash. That will create a circular reference.
     bless {
         session => $env->{'psgix.session'},
         options => $env->{'psgix.session.options'},
@@ -74,11 +72,13 @@ Plack::Session - Middleware for session management
 =head1 SYNOPSIS
 
   # Use with Middleware::Session
-  enable "Session", session_class => "Plack::Session";
+  enable "Session";
 
+  # later in your app
+  use Plack::Session;
   my $app = sub {
       my $env = shift;
-      my $session = $env->{'plack.session'}; # not psgix.
+      my $session = Plack::Session->new($env);
 
       $session->id;
       $session->get($key);
index 8d2b517..1103bf7 100644 (file)
@@ -6,16 +6,15 @@ use HTTP::Cookies;
 
 my $app = sub {
     my $env = shift;
-    my $counter = $env->{'plack.session'}->get('counter') || 0;
+    my $counter = $env->{'psgix.session'}->{counter} || 0;
 
     my $body = "Counter=$counter";
-    $counter++;
-    $env->{'plack.session'}->set(counter => $counter);
+    $env->{'psgix.session'}->{counter} = $counter + 1;
 
     return [ 200, [], [ $body ] ];
 };
 
-$app = Plack::Middleware::Session->wrap($app, session_class => "Plack::Session");
+$app = Plack::Middleware::Session->wrap($app);
 
 test_psgi $app, sub {
     my $cb = shift;
index c35f34d..c0596d4 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 use Plack::Middleware::Session;
+use Plack::Session;
 
 sub create_session {
     my($mw, $env) = @_;
@@ -12,7 +13,7 @@ sub create_session {
     my $session;
     my $app = sub {
         my $env = shift;
-        $session = $env->{'plack.session'};
+        $session = Plack::Session->new($env);
         return sub {
             my $responder = shift;
             $responder->([ 200, [], [] ]);
@@ -39,7 +40,7 @@ sub run_all_tests {
         response_test
     ]};
 
-    my $m = sub { Plack::Middleware::Session->wrap($_[0], session_class => "Plack::Session", state => $state, store => $storage) };
+    my $m = sub { Plack::Middleware::Session->wrap($_[0], state => $state, store => $storage) };
 
     $response_test ||= sub {
         my($res_cb, $session_id, $check_expired) = @_;