Skip to content

Instantly share code, notes, and snippets.

@hisaichi5518
Created March 18, 2014 09:36
Show Gist options
  • Save hisaichi5518/9616700 to your computer and use it in GitHub Desktop.
Save hisaichi5518/9616700 to your computer and use it in GitHub Desktop.
diff --git a/lib/Plack/Request/WithEncoding.pm b/lib/Plack/Request/WithEncoding.pm
index 45d3d3f..aa8f36b 100644
--- a/lib/Plack/Request/WithEncoding.pm
+++ b/lib/Plack/Request/WithEncoding.pm
@@ -81,11 +81,34 @@ sub _decode_parameters {
my @flatten = $stuff->flatten;
my @decoded;
while ( my ($k, $v) = splice @flatten, 0, 2 ) {
- push @decoded, $encoding->decode($k), $encoding->decode($v);
+ push @decoded, $self->__decode($encoding, $k), $self->__decode($encoding, $v);
}
return Hash::MultiValue->new(@decoded);
}
_
+sub __decode {
+ my ($self, $encoding, $data) = @_;
+
+ if (ref $data eq "ARRAY") {
+ my @result;
+ for my $d (@$data) {
+ push @result, $self->__decode($encoding, $d);
+ }
+
+ return \@result;
+ }
+ elsif (ref $data eq "HASH") {
+ my %result;
+ while (my ($k, $v) = each %$data) {
+ $result{$self->__decode($encoding, $k)} = $self->__decode($encoding, $v);
+ }
+
+ return \%result;
+ }
+
+ return $encoding->decode($data);
+}
+
1;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment