]> wagnertech.de Git - mfinanz.git/commitdiff
flash_later durch Auto-Restore von 'FLASH' von Session nach $::form gefixt
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 17 Jun 2011 13:12:43 +0000 (15:12 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 17 Jun 2011 13:12:43 +0000 (15:12 +0200)
Bug wurde in c90b4dcd implementiert. Hintergrund:

c90b4dcd sollte ermöglichen, dass Werte in der Session gespeichert
werden, die aber nicht automatisch nach $::form zurück kopiert
werden. Das wird nun fürs Speichern der Form in der Session
benutzt (Stichwort: previousform/callback).

Es war aber seitdem nicht möglich, einer zu speichernden komplexen
Datenstruktur zu sagen, dass sie doch automatisch nach $::form zurück
kopiert werden soll. Der Flash ist ein solcher Fall, genauer: der
einzige, bei dem passieren soll.

Also das Interface von $::auth->set_session_value so erweitert, dass
der auto_restore-Parameter gesetzt werden kann, und Flash so geändert,
dass flash_later dieses nun auch tut.

SL/Auth.pm
SL/Helper/Flash.pm

index 9398f557bf967854b0cf7d525692a49db0c35624..b1e4b25e93d57887d33412eff207b777c0982141 100644 (file)
@@ -673,12 +673,23 @@ sub set_session_value {
   $main::lxdebug->enter_sub();
 
   my $self   = shift;
   $main::lxdebug->enter_sub();
 
   my $self   = shift;
-  my %params = @_;
+  my @params = @_;
 
   $self->{SESSION} ||= { };
 
 
   $self->{SESSION} ||= { };
 
-  while (my ($key, $value) = each %params) {
-    $self->{SESSION}->{ $key } = YAML::Dump(ref($value) eq 'HASH' ? { data => $value } : $value);
+  while (@params) {
+    my $key = shift @params;
+
+    if (ref $key eq 'HASH') {
+      my $value = { data         => $key->{value},
+                    auto_restore => $key->{auto_restore},
+                  };
+      $self->{SESSION}->{ $key->{key} } = YAML::Dump($value);
+
+    } else {
+      my $value = shift @params;
+      $self->{SESSION}->{ $key } = YAML::Dump(ref($value) eq 'HASH' ? { data => $value } : $value);
+    }
   }
 
   $main::lxdebug->leave_sub();
   }
 
   $main::lxdebug->leave_sub();
@@ -1186,11 +1197,30 @@ SL::Auth - Authentication and session handling
 
 =over 4
 
 
 =over 4
 
+=item C<set_session_value @values>
 =item C<set_session_value %values>
 
 =item C<set_session_value %values>
 
-Store all key/value pairs in C<%values> in the session. All of these
-values are copied back into C<$::form> in the next request
-automatically.
+Store all values of C<@values> or C<%values> in the session. Each
+member of C<@values> is tested if it is a hash reference. If it is
+then it must contain the keys C<key> and C<value> and can optionally
+contain the key C<auto_restore>. In this case C<value> is associated
+with C<key> and restored to C<$::form> upon the next request
+automatically if C<auto_restore> is trueish or if C<value> is a scalar
+value.
+
+If the current member of C<@values> is not a hash reference then it
+will be used as the C<key> and the next entry of C<@values> is used as
+the C<value> to store. In this case setting C<auto_restore> is not
+possible.
+
+Therefore the following two invocations are identical:
+
+  $::auth-E<gt>set_session_value(name =E<gt> "Charlie");
+  $::auth-E<gt>set_session_value({ key =E<gt> "name", value =E<gt> "Charlie" });
+
+All of these values are copied back into C<$::form> for the next
+request automatically if they're scalar values or if they have
+C<auto_restore> set to trueish.
 
 The values can be any Perl structure. They are stored as YAML dumps.
 
 
 The values can be any Perl structure. They are stored as YAML dumps.
 
index 876de964436d86f759f16292114371c1cc1965da..78a94e34f0aef463c5b1cedb4371a74cd39f24a1 100644 (file)
@@ -16,7 +16,7 @@ sub flash {
 }
 
 sub flash_later {
 }
 
 sub flash_later {
-  $::auth->set_session_value(FLASH => _store_flash($::auth->get_session_value('FLASH'), @_));
+  $::auth->set_session_value({ key => "FLASH", value => _store_flash($::auth->get_session_value('FLASH'), @_), auto_restore => 1 });
 }
 
 sub render_flash {
 }
 
 sub render_flash {