Permalink
Browse files

remove older Plack support from Unicode plugin

  • Loading branch information...
1 parent 44ea6fd commit 76f3da31026ded491a0a1c71b5f540f78d36a1f3 @typester committed Dec 7, 2012
Showing with 23 additions and 23 deletions.
  1. +1 −1 Makefile.PL
  2. +18 −19 lib/Ark/Plugin/Encoding/Unicode.pm
  3. +4 −3 t/plugin_unicode.t
View
@@ -5,7 +5,7 @@ license 'perl';
all_from 'lib/Ark.pm';
-test_requires 'Test::More';
+test_requires 'Test::More' => '0.96';
test_requires 'Test::Output';
perl_version '5.008001';
@@ -2,38 +2,37 @@ package Ark::Plugin::Encoding::Unicode;
use Ark::Plugin;
use Scalar::Util 'blessed';
+use Encode;
+
sub prepare_encoding {
my $self = shift;
my $req = $self->request;
my $encode = sub {
- my ($p, $skip) = @_;
-
- if (blessed $p and $p->isa('Hash::MultiValue')) {
- return if $skip;
- $p->each(sub {
- utf8::decode($_[1]);
- });
- }
- else {
- # backward compat
- for my $value (values %$p) {
- next if ref $value and ref $value ne 'ARRAY';
- utf8::decode($_) for ref $value ? @$value : ($value);
- }
- }
+ my ($p) = @_;
+
+ my $decoded = Hash::MultiValue->new;
+
+ $p->each(sub {
+ $decoded->add( $_[0], decode_utf8($_[1]) );
+ });
+
+ $decoded;
};
- $encode->($req->query_parameters);
- $encode->($req->body_parameters);
- $encode->($req->parameters, 1)
+ $req->env->{'plack.request.query'} = $encode->($req->query_parameters);
+ $req->env->{'plack.request.body'} = $encode->($req->body_parameters);
+
+ if ($req->env->{'plack.request.merged'}) {
+ $req->env->{'plack.request.merged'} = $encode->($req->env->{'plack.request.merged'});
+ }
};
sub finalize_encoding {
my $self = shift;
my $res = $self->response;
- utf8::encode( $res->{body} ) if !$res->binary and $res->has_body;
+ $res->body(encode_utf8 $res->body ) if !$res->binary and $res->has_body;
};
1;
View
@@ -1,4 +1,6 @@
-use Test::Base;
+use strict;
+use warnings;
+use Test::More;
{
package TestApp;
@@ -27,8 +29,6 @@ use Test::Base;
use Ark::Test 'TestApp',
components => [qw/Controller::Root/];
-plan 'no_plan';
-
use URI;
my $uri = URI->new('/');
$uri->query_form({ foo => 'テスト' });
@@ -38,3 +38,4 @@ ok($res->is_success, 'request ok');
ok(!utf8::is_utf8($res->content), 'response is binary');
is($res->content, 'テスト', 'response content ok');
+done_testing;

0 comments on commit 76f3da3

Please sign in to comment.