Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 777bf75c

Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt

  • ID 777bf75cfcfc81a87479a508ea900de4a64c483e
  • Vorgänger e5478aea
  • Nachfolger baba1fe9

Eine Hilfsfunktion, die aus Array- und Hashstrukturen in $form eine Liste von Variablennamen und Werten erzeugt, die dann wieder als versteckte Inputs in HTML-Formularen ausgegeben werden kann. Dabei sind die Variablennamen strukturiert (so wird z.B. aus "$form->{filter}->[0]->{description}" der Name "filter[+].description"). Außerdem eine Anpassung von $form->isblank(), die solch strukturierte Variablennamen versteht.

Unterschiede anzeigen:

SL/Form.pm
return $self;
}
sub _flatten_variables_rec {
$main::lxdebug->enter_sub(2);
my $self = shift;
my $curr = shift;
my $prefix = shift;
my $key = shift;
my @result;
if ('' eq ref $curr->{$key}) {
@result = ({ 'key' => $prefix . $key, 'value' => $curr->{$key} });
} elsif ('HASH' eq ref $curr->{$key}) {
foreach my $hash_key (sort keys %{ $curr->{$key} }) {
push @result, $self->_flatten_variables_rec($curr->{$key}, $prefix . $key . '.', $hash_key);
}
} else {
foreach my $idx (0 .. scalar @{ $curr->{$key} } - 1) {
my $first_array_entry = 1;
foreach my $hash_key (sort keys %{ $curr->{$key}->[$idx] }) {
push @result, $self->_flatten_variables_rec($curr->{$key}->[$idx], $prefix . $key . ($first_array_entry ? '[+].' : '[].'), $hash_key);
$first_array_entry = 0;
}
}
}
$main::lxdebug->leave_sub(2);
return @result;
}
sub flatten_variables {
$main::lxdebug->enter_sub(2);
my $self = shift;
my @keys = @_;
my @variables;
foreach (@keys) {
push @variables, $self->_flatten_variables_rec($self, '', $_);
}
$main::lxdebug->leave_sub(2);
return @variables;
}
sub debug {
$main::lxdebug->enter_sub();
......
my ($self, $name, $msg) = @_;
if ($self->{$name} =~ /^\s*$/) {
$self->error($msg);
my $curr = $self;
foreach my $part (split '.', $name) {
if (!$curr->{$part} || ($curr->{$part} =~ /^\s*$/)) {
$self->error($msg);
}
$curr = $curr->{$part};
}
$main::lxdebug->leave_sub();
}

Auch abrufbar als: Unified diff