Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bc9d2f36

Von Moritz Bunkus vor etwa 14 Jahren hinzugefügt

  • ID bc9d2f36944158fedf0e4229fb3b4f241933f60e
  • Vorgänger a609123f
  • Nachfolger 508801bb

flash_later durch Auto-Restore von 'FLASH' von Session nach $::form gefixt

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.

Unterschiede anzeigen:

SL/Auth.pm
$main::lxdebug->enter_sub();
my $self = shift;
my %params = @_;
my @params = @_;
$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();
......
=over 4
=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.

Auch abrufbar als: Unified diff