[Catalyst-commits] r11465 - in Catalyst-Plugin-Session/0.00/trunk: . lib/Catalyst/Plugin t t/lib t/lib/FlashTestApp t/lib/FlashTestApp/Controller t/lib/SessionTestApp t/lib/SessionTestApp/Controller

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Oct 6 08:36:40 GMT 2009


Author: t0m
Date: 2009-10-06 08:36:39 +0000 (Tue, 06 Oct 2009)
New Revision: 11465

Added:
   Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp/
   Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp/Controller/
   Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp/Controller/Root.pm
   Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/
   Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/
   Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm
Modified:
   Catalyst-Plugin-Session/0.00/trunk/
   Catalyst-Plugin-Session/0.00/trunk/Changes
   Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm
   Catalyst-Plugin-Session/0.00/trunk/t/01_setup.t
   Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp.pm
   Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp.pm
Log:
Tidy up config namespace and the TestApps


Property changes on: Catalyst-Plugin-Session/0.00/trunk
___________________________________________________________________
Name: svn:ignore
   - inc
Makefile
Makefile.old
MANIFEST
README
META.yml
Build
_build
blib

   + pm_to_blib
inc
Makefile
Makefile.old
MANIFEST
README
META.yml
Build
_build
blib


Modified: Catalyst-Plugin-Session/0.00/trunk/Changes
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/Changes	2009-10-05 22:59:11 UTC (rev 11464)
+++ Catalyst-Plugin-Session/0.00/trunk/Changes	2009-10-06 08:36:39 UTC (rev 11465)
@@ -1,5 +1,11 @@
 Revision history for Perl extension Catalyst::Plugin::Session
 
+        - Move actions out of the root application class in tests as this
+          is deprecated.
+        - Change configuration key to 'Plugin::Session' by default. The
+          old 'session' key is still supported, but will issue a warning
+          in a future release.
+
 0.26 2009-08-19
         - Remove Test::MockObject from the test suite as prone to failing on
           some platforms and perl versions due to it's UNIVERSAL:: package

Modified: Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm	2009-10-05 22:59:11 UTC (rev 11464)
+++ Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm	2009-10-06 08:36:39 UTC (rev 11465)
@@ -35,6 +35,14 @@
           /
 );
 
+sub _session_plugin_config {
+    my $c = shift;
+    # FIXME - Start warning once all the state/store modules have also been updated.
+    #$c->log->warn("Deprecated 'session' config key used, please use the key 'Plugin::Session' instead")
+    #    if exists $c->config->{session}
+    #$c->config->{'Plugin::Session'} ||= delete($c->config->{session}) || {};
+    $c->config->{'Plugin::Session'} ||= $c->config->{session} || {};
+}
 
 sub setup {
     my $c = shift;
@@ -65,7 +73,7 @@
 sub setup_session {
     my $c = shift;
 
-    my $cfg = ( $c->config->{session} ||= {} );
+    my $cfg = $c->_session_plugin_config;
 
     %$cfg = (
         expires        => 7200,
@@ -82,7 +90,7 @@
 
     $c->maybe::next::method(@_);
 
-    if (    $c->config->{session}{flash_to_stash}
+    if (    $c->_session_plugin_config->{flash_to_stash}
         and $c->sessionid
         and my $flash_data = $c->flash )
     {
@@ -215,7 +223,7 @@
             $c->_session($session_data);
 
             no warnings 'uninitialized';    # ne __address
-            if (   $c->config->{session}{verify_address}
+            if (   $c->_session_plugin_config->{verify_address}
                 && $session_data->{__address} ne $c->request->address )
             {
                 $c->log->warn(
@@ -226,7 +234,7 @@
                 $c->delete_session("address mismatch");
                 return;
             }
-            if (   $c->config->{session}{verify_user_agent}
+            if (   $c->_session_plugin_config->{verify_user_agent}
                 && $session_data->{__user_agent} ne $c->request->user_agent )
             {
                 $c->log->warn(
@@ -353,7 +361,7 @@
 
 sub calculate_initial_session_expires {
     my $c = shift;
-    return ( time() + $c->config->{session}{expires} );
+    return ( time() + $c->_session_plugin_config->{expires} );
 }
 
 sub calculate_extended_session_expires {
@@ -480,12 +488,12 @@
             __updated => $now,
 
             (
-                $c->config->{session}{verify_address}
+                $c->_session_plugin_config->{verify_address}
                 ? ( __address => $c->request->address||'' )
                 : ()
             ),
             (
-                $c->config->{session}{verify_user_agent}
+                $c->_session_plugin_config->{verify_user_agent}
                 ? ( __user_agent => $c->request->user_agent||'' )
                 : ()
             ),
@@ -756,7 +764,7 @@
 
 For example:
 
-    __PACKAGE__->config->{session}{expires} = 1000000000000; # forever
+    __PACKAGE__->config('Plugin::Session' => { expires => 1000000000000 }); # forever
 
     # later
 
@@ -810,7 +818,7 @@
 
 =item setup_session
 
-This method populates C<< $c->config->{session} >> with the default values
+This method populates C<< $c->config('Plugin::Session') >> with the default values
 listed in L</CONFIGURATION>.
 
 =item prepare_action
@@ -954,12 +962,12 @@
 
 =head1 CONFIGURATION
 
-    $c->config->{session} = {
+    $c->config('Plugin::Session' => {
         expires => 1234,
-    };
+    });
 
 All configuation parameters are provided in a hash reference under the
-C<session> key in the configuration hash.
+C<Plugin::Session> key in the configuration hash.
 
 =over 4
 

Modified: Catalyst-Plugin-Session/0.00/trunk/t/01_setup.t
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/01_setup.t	2009-10-05 22:59:11 UTC (rev 11464)
+++ Catalyst-Plugin-Session/0.00/trunk/t/01_setup.t	2009-10-06 08:36:39 UTC (rev 11465)
@@ -64,7 +64,7 @@
 is( $calls, 0, "no fatal error logged either" );
 
 cmp_deeply(
-    [ keys %{ $config{session} } ],
+    [ keys %{ $config{'Plugin::Session'} } ],
     bag(qw/expires verify_address verify_user_agent/),
     "default values for config were populated in successful setup",
 );

Added: Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp/Controller/Root.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp/Controller/Root.pm	                        (rev 0)
+++ Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp/Controller/Root.pm	2009-10-06 08:36:39 UTC (rev 11465)
@@ -0,0 +1,58 @@
+package FlashTestApp::Controller::Root;
+use strict;
+use warnings;
+use Data::Dumper;
+
+use base qw/Catalyst::Controller/;
+
+__PACKAGE__->config( namespace => '' );
+
+no warnings 'uninitialized';
+
+sub default : Private {
+    my ($self, $c) = @_;
+    $c->session;
+}
+    
+sub first : Global {
+    my ( $self, $c ) = @_;
+    if ( ! $c->flash->{is_set}) {
+        $c->stash->{message} = "flash is not set";
+        $c->flash->{is_set} = 1;
+    }
+}
+
+sub second : Global {
+    my ( $self, $c ) = @_;
+    if ($c->flash->{is_set} == 1){
+        $c->stash->{message} = "flash set first time";
+        $c->flash->{is_set}++;
+    }
+}
+
+sub third : Global {
+    my ( $self, $c ) = @_;
+    if ($c->flash->{is_set} == 2) {
+        $c->stash->{message} = "flash set second time";
+        $c->keep_flash("is_set");
+    }
+}
+
+sub fourth : Global {
+    my ( $self, $c ) = @_;
+    if ($c->flash->{is_set} == 2) {
+        $c->stash->{message} = "flash set 3rd time, same val as prev."
+    }
+}
+
+sub fifth : Global {
+    my ( $self, $c ) = @_;
+    $c->forward('/first');
+}
+
+sub end : Private {
+    my ($self, $c) = @_;
+    $c->res->output($c->stash->{message});
+}
+
+1;

Modified: Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp.pm	2009-10-05 22:59:11 UTC (rev 11464)
+++ Catalyst-Plugin-Session/0.00/trunk/t/lib/FlashTestApp.pm	2009-10-06 08:36:39 UTC (rev 11465)
@@ -1,60 +1,11 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
 
 package FlashTestApp;
 use Catalyst qw/Session Session::Store::Dummy Session::State::Cookie/;
 
 use strict;
 use warnings;
-no warnings 'uninitialized';
 
-sub default : Private {
-    my ($self, $c) = @_;
-    $c->session;
-}
-
-    
-sub first : Global {
-    my ( $self, $c ) = @_;
-    if ( ! $c->flash->{is_set}) {
-        $c->stash->{message} = "flash is not set";
-        $c->flash->{is_set} = 1;
-    }
-}
-
-sub second : Global {
-    my ( $self, $c ) = @_;
-    if ($c->flash->{is_set} == 1){
-        $c->stash->{message} = "flash set first time";
-        $c->flash->{is_set}++;
-    }
-}
-
-sub third : Global {
-    my ( $self, $c ) = @_;
-    if ($c->flash->{is_set} == 2) {
-        $c->stash->{message} = "flash set second time";
-        $c->keep_flash("is_set");
-    }
-}
-
-sub fourth : Global {
-    my ( $self, $c ) = @_;
-    if ($c->flash->{is_set} == 2) {
-        $c->stash->{message} = "flash set 3rd time, same val as prev."
-    }
-}
-
-sub fifth : Global {
-    my ( $self, $c ) = @_;
-    $c->forward('/first');
-}
-
-sub end : Private {
-    my ($self, $c) = @_;
-    $c->res->output($c->stash->{message});
-}
-
-
 __PACKAGE__->setup;
 
 __PACKAGE__;

Added: Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm	                        (rev 0)
+++ Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm	2009-10-06 08:36:39 UTC (rev 11465)
@@ -0,0 +1,70 @@
+package SessionTestApp::Controller::Root;
+use strict;
+use warnings;
+use Data::Dumper;
+
+use base qw/Catalyst::Controller/;
+
+__PACKAGE__->config( namespace => '' );
+
+sub login : Global {
+    my ( $self, $c ) = @_;
+    $c->session;
+    $c->res->output("logged in");
+}
+
+sub logout : Global {
+    my ( $self, $c ) = @_;
+    $c->res->output(
+        "logged out after " . $c->session->{counter} . " requests" );
+    $c->delete_session("logout");
+}
+
+sub set_session_variable : Global {
+    my ( $self, $c, $var, $val ) = @_;
+    $c->session->{$var} = $val;
+    $c->res->output("session variable set");
+}
+
+sub get_session_variable : Global {
+    my ( $self, $c, $var ) = @_;
+    my $val = $c->session->{$var} || 'n.a.';
+    $c->res->output("VAR_$var=$val");
+}
+
+sub get_sessid : Global {
+    my ( $self, $c ) = @_;
+    my $sid = $c->sessionid || 'n.a.';
+    $c->res->output("SID=$sid");
+}
+
+sub dump_session : Global {
+    my ( $self, $c ) = @_;
+    my $sid = $c->sessionid || 'n.a.';
+    my $dump = Dumper($c->session || 'n.a.');
+    $c->res->output("[SID=$sid]\n$dump");
+}
+
+sub change_sessid : Global {
+    my ( $self, $c ) = @_;
+    $c->change_session_id;
+    $c->res->output("session id changed");
+}
+
+sub page : Global {
+    my ( $self, $c ) = @_;
+    if ( $c->session_is_valid ) {
+        $c->res->output("you are logged in, session expires at " . $c->session_expires);
+        $c->session->{counter}++;
+    }
+    else {
+        $c->res->output("please login");
+    }
+}
+
+sub user_agent : Global {
+    my ( $self, $c ) = @_;
+    $c->res->output('UA=' . $c->req->user_agent);
+}
+
+1;

Modified: Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp.pm	2009-10-05 22:59:11 UTC (rev 11464)
+++ Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp.pm	2009-10-06 08:36:39 UTC (rev 11465)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 
 package SessionTestApp;
 use Catalyst qw/Session Session::Store::Dummy Session::State::Cookie/;
@@ -6,73 +6,11 @@
 use strict;
 use warnings;
 
-use Data::Dumper;
-
-__PACKAGE__->config->{session} = {
+__PACKAGE__->config('Plugin::Session' => {
     # needed for live_verify_user_agent.t; should be harmless for other tests 
     verify_user_agent => 1,  
-};
+});
 
-sub login : Global {
-    my ( $self, $c ) = @_;
-    $c->session;
-    $c->res->output("logged in");
-}
-
-sub logout : Global {
-    my ( $self, $c ) = @_;
-    $c->res->output(
-        "logged out after " . $c->session->{counter} . " requests" );
-    $c->delete_session("logout");
-}
-
-sub set_session_variable : Global {
-    my ( $self, $c, $var, $val ) = @_;
-    $c->session->{$var} = $val;
-    $c->res->output("session variable set");
-}
-
-sub get_session_variable : Global {
-    my ( $self, $c, $var ) = @_;
-    my $val = $c->session->{$var} || 'n.a.';
-    $c->res->output("VAR_$var=$val");
-}
-
-sub get_sessid : Global {
-    my ( $self, $c ) = @_;
-    my $sid = $c->sessionid || 'n.a.';
-    $c->res->output("SID=$sid");
-}
-
-sub dump_session : Global {
-    my ( $self, $c ) = @_;
-    my $sid = $c->sessionid || 'n.a.';
-    my $dump = Dumper($c->session || 'n.a.');
-    $c->res->output("[SID=$sid]\n$dump");
-}
-
-sub change_sessid : Global {
-    my ( $self, $c ) = @_;
-    $c->change_session_id;
-    $c->res->output("session id changed");
-}
-
-sub page : Global {
-    my ( $self, $c ) = @_;
-    if ( $c->session_is_valid ) {
-        $c->res->output("you are logged in, session expires at " . $c->session_expires);
-        $c->session->{counter}++;
-    }
-    else {
-        $c->res->output("please login");
-    }
-}
-
-sub user_agent : Global {
-    my ( $self, $c ) = @_;
-    $c->res->output('UA=' . $c->req->user_agent);
-}
-
 __PACKAGE__->setup;
 
 __PACKAGE__;




More information about the Catalyst-commits mailing list