[Catalyst-commits] r11745 - in Catalyst-Plugin-Session/0.00/trunk:
. lib/Catalyst/Plugin t t/lib/SessionTestApp/Controller
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Wed Nov 4 22:39:47 GMT 2009
Author: t0m
Date: 2009-11-04 22:39:46 +0000 (Wed, 04 Nov 2009)
New Revision: 11745
Added:
Catalyst-Plugin-Session/0.00/trunk/t/live_accessor.t
Modified:
Catalyst-Plugin-Session/0.00/trunk/
Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm
Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm
Log:
r11709 at t0mlaptop (orig r11674): hobbs | 2009-10-27 09:29:57 +0000
Once again I fail at branching. Let's put the branch in branches/ shall we?
r11710 at t0mlaptop (orig r11675): hobbs | 2009-10-27 09:48:02 +0000
Code, test, docs.
Property changes on: Catalyst-Plugin-Session/0.00/trunk
___________________________________________________________________
Name: svk:merge
+ 4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Plugin-Session/0.00/branches/accessor_change:11675
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Plugin-Session:10129
Modified: Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm 2009-11-04 21:38:49 UTC (rev 11744)
+++ Catalyst-Plugin-Session/0.00/trunk/lib/Catalyst/Plugin/Session.pm 2009-11-04 22:39:46 UTC (rev 11745)
@@ -425,10 +425,21 @@
sub session {
my $c = shift;
- $c->_session || $c->_load_session || do {
+ my $session = $c->_session || $c->_load_session || do {
$c->create_session_id_if_needed;
$c->initialize_session_data;
};
+
+ if (@_) {
+ my $new_values = @_ > 1 ? { @_ } : $_[0];
+ croak('session takes a hash or hashref') unless ref $new_values;
+
+ for my $key (keys %$new_values) {
+ $session->{$key} = $new_values->{$key};
+ }
+ }
+
+ $session;
}
sub keep_flash {
@@ -678,6 +689,13 @@
This method will automatically create a new session and session ID if none
exists.
+You can also set session keys by passing a list of key/value pairs or a
+hashref.
+
+ $c->session->{foo} = "bar"; # This works.
+ $c->session(one => 1, two => 2); # And this.
+ $c->session({ answer => 42 }); # And this.
+
=item session_expires
=item session_expires $reset
Modified: Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm 2009-11-04 21:38:49 UTC (rev 11744)
+++ Catalyst-Plugin-Session/0.00/trunk/t/lib/SessionTestApp/Controller/Root.pm 2009-11-04 22:39:46 UTC (rev 11745)
@@ -67,4 +67,25 @@
$c->res->output('UA=' . $c->req->user_agent);
}
+sub accessor_test : Global {
+ my ( $self, $c ) = @_;
+
+ $c->session(
+ one => 1,
+ two => 2,
+ );
+
+ $c->session( {
+ three => 3,
+ four => 4,
+ },
+ );
+
+ $c->session->{five} = 5;
+
+ for my $key (keys %{ $c->session }) {
+ $c->res->write("$key: " . $c->session->{$key} . "\n");
+ }
+}
+
1;
Added: Catalyst-Plugin-Session/0.00/trunk/t/live_accessor.t
===================================================================
--- Catalyst-Plugin-Session/0.00/trunk/t/live_accessor.t (rev 0)
+++ Catalyst-Plugin-Session/0.00/trunk/t/live_accessor.t 2009-11-04 22:39:46 UTC (rev 11745)
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+#
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+ eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) }
+ or plan skip_all =>
+ "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test";
+
+ eval {
+ require Test::WWW::Mechanize::Catalyst;
+ Test::WWW::Mechanize::Catalyst->VERSION(0.51);
+ }
+ or plan skip_all =>
+ 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test';
+
+ plan tests => 4;
+}
+
+use lib "t/lib";
+use Test::WWW::Mechanize::Catalyst "SessionTestApp";
+
+my $ua = Test::WWW::Mechanize::Catalyst->new;
+
+$ua->get_ok("http://localhost/accessor_test", "Set session vars okay");
+
+$ua->content_contains("two: 2", "k/v list setter works okay");
+
+$ua->content_contains("four: 4", "hashref setter works okay");
+
+$ua->content_contains("five: 5", "direct access works okay");
+
More information about the Catalyst-commits
mailing list