From: Sven Schöling Date: Mon, 7 Jan 2013 11:58:21 +0000 (+0100) Subject: flatten_variables auch die var[] syntax beigebracht X-Git-Tag: release-3.1.0beta1~401^2~12 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a45d8cbe5ee45a89a61465a1e2c4a43b74ed375d;p=kivitendo-erp.git flatten_variables auch die var[] syntax beigebracht --- diff --git a/SL/Form.pm b/SL/Form.pm index 30c8bd425..77aea90cf 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -138,9 +138,15 @@ sub _flatten_variables_rec { 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; + my $element = $curr->{$key}[$idx]; + + if ('HASH' eq ref $element) { + foreach my $hash_key (sort keys %{ $element }) { + push @result, $self->_flatten_variables_rec($element, $prefix . $key . ($first_array_entry ? '[+].' : '[].'), $hash_key); + $first_array_entry = 0; + } + } else { + @result = ({ 'key' => $prefix . $key . ($first_array_entry ? '[+]' : '[]'), 'value' => $element }); } } }