Merge 'accessor_change' into 'trunk'
Tomas Doran [Wed, 4 Nov 2009 22:39:46 +0000 (22:39 +0000)]
r11709@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@t0mlaptop (orig r11675):  hobbs | 2009-10-27 09:48:02 +0000
Code, test, docs.

1  2 
lib/Catalyst/Plugin/Session.pm

@@@ -13,7 -13,7 +13,7 @@@ use Carp
  
  use namespace::clean -except => 'meta';
  
 -our $VERSION = '0.27';
 +our $VERSION = '0.28';
  $VERSION = eval $VERSION;
  
  my @session_data_accessors; # used in delete_session
@@@ -425,10 -425,21 +425,21 @@@ sub validate_session_id 
  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 +689,13 @@@ requests
  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
@@@ -1104,10 -1122,6 +1122,10 @@@ Sergio Salv
  
  kmx C<kmx@volny.cz>
  
 +Florian Ragwitz (rafl) C<rafl@debian.org>
 +
 +Kent Fredric (kentnl)
 +
  And countless other contributers from #catalyst. Thanks guys!
  
  =head1 COPYRIGHT & LICENSE