From: Aristotle Pagaltzis Date: Mon, 16 Feb 2015 16:53:36 +0000 (+0100) Subject: reuse mixed-values hash logic from Hash::MultiValue X-Git-Tag: 5.90083~2^2^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=2a2b8f6504e0e8adc7d7b78435ffdcd27c37fc15 reuse mixed-values hash logic from Hash::MultiValue There is no need to have code for the same job in memory twice, or two fix bugs in two copies of code for doing the same thing. --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index cac63de..44c9c12 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -587,41 +587,15 @@ sub prepare_query_parameters { return; } - my %query; + $query_string =~ s/\A[&;]+//; - # replace semi-colons - $query_string =~ s/;/&/g; + my $p = Hash::MultiValue->new( + map { defined $_ ? decode_utf8($self->unescape_uri($_)) : $_ } + map { ( split /=/, $_, 2 )[0,1] } # slice forces two elements + split /[&;]+/, $query_string + ); - my @params = grep { length $_ } split /&/, $query_string; - - for my $item ( @params ) { - - my ($param, $value) - = map { decode_utf8($self->unescape_uri($_)) } - split( /=/, $item, 2 ); - - unless(defined $param) { - $param = $self->unescape_uri($item); - $param = decode_utf8 $param; - } - - if ( exists $query{$param} ) { - if ( ref $query{$param} ) { - push @{ $query{$param} }, $value; - } - else { - $query{$param} = [ $query{$param}, $value ]; - } - } - else { - $query{$param} = $value; - } - } - - $c->request->query_parameters( - $c->request->_use_hash_multivalue ? - Hash::MultiValue->from_mixed(\%query) : - \%query); + $c->request->query_parameters( $c->request->_use_hash_multivalue ? $p : $p->mixed ); } =head2 $self->prepare_read($c)