http://qs1969.pair.com?node_id=11112828


in reply to How to loop through Plack::Request body_parameters ?

Anonymonk covered Hash::MultiValue. All you need–

my $params = $form->body_parameters->as_hashref; # or my %params = %{$form->body_parameters};

Some tips. use strict 'refs' is code smell. It’s half way to not using strict at all which is, for any code longer than you can easily understand in a glace, like swimming while carrying a brick.

I was surprised to see that the following is apparently reliable and even approximately shown in the docs for keys. I was surprised because hash keys are “unordered” so this looks funky but the values and keys are “unordered” in the same way so… Anyway, it seems a bit too clever to me and might lead you to believe you can rely on order between different hashes.

my @k = keys %$form; my @v = values %$form; @form_hash{@k} = @v;

I am absolutely not trying to dissuade you from learning and experimenting. That said, Plack is not meant for what it seems like you’re doing. It’s a low level toolkit, not a web application framework. Keep playing around. It’s fun. Consider picking up Mojolicious or another webapp framework if you’re serious about making code for anyone but yourself. There are many parts that are either done already or make everything much easier. The suggestion about Plack::App::WrapCGI may also be cromulent. Your old FCGI code could likely just be wrapped up. The CGI code has to be pretty clean but the error feedback is quite good, though nothing you’d ever want to expose to users, so…