Created
June 8, 2020 14:11
-
-
Save jjn1056/51514db7e2e4ef5b097e80190a64055b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(0) { | |
use Devel::Dwarn; | |
Dwarn $c->req->_body; | |
my $new = (); | |
my %params = %{$c->req->body_parameters||+{}}; | |
Dwarn \%params; | |
my $current_path; | |
my %current_path_index; | |
my $cb; $cb = sub { | |
my ($base, $next, @parts) = @_; | |
if(ref $next eq 'ARRAY') { | |
if(length($next->[0])) { | |
$next = $next->[0]; | |
} else { | |
$next = scalar(@{$$base||[]}); | |
$current_path_index{$current_path}++; | |
#$next-- if $reset; | |
} | |
# $current_path .= length($next->[0]) ? ".$next->[0]" : "._X_"; | |
# $current_path_index{$current_path} = length($next->[0]) ? $next->[0] : 3; | |
# $next = length($next->[0]) ? $next->[0] : scalar(@{$$base||[]}); | |
#$next-- if $reset; | |
# $reset = 0; | |
warn "... $current_path . $next.. @{ $current_path_index{$current_path} ||'NA' } .. \n"; | |
return scalar(@parts) ? | |
$cb->( \($$base->[ $next ]), @parts) : | |
do { $$base = [ $next ]; \$base }; | |
} else { | |
$current_path .= ".$next"; | |
warn "... $current_path \n"; | |
return scalar(@parts) ? | |
$cb->( \($$base->{$next}), @parts) : | |
do { $$base = $next; \$base }; | |
} | |
}; | |
my %value_index = (); | |
my @keys = @{ $c->req->_body->param_order ||[] }; | |
foreach my $key (@keys) { | |
my @values = ref($params{$key}) eq 'ARRAY' ? @{$params{$key}} : $params{$key}; | |
my $value = $values[ $value_index{$key}||0 ]; | |
$value_index{$key}++; | |
my (@key_parts) = map { | |
my (@bits) = ($_ =~ m/(^.+)\[(.*)\]$/); | |
@bits ? ($bits[0], [$bits[1]]) : $_; | |
} (split(/\./, $key), $value); | |
$current_path = ''; | |
$cb->(\$new, @key_parts); | |
} | |
warn "..." x 10; | |
Dwarn $new; | |
die 1 if %params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment