Skip to content

Commit

Permalink
remove older Plack support from Unicode plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
typester committed Dec 7, 2012
1 parent 44ea6fd commit 76f3da3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license 'perl';


all_from 'lib/Ark.pm'; all_from 'lib/Ark.pm';


test_requires 'Test::More'; test_requires 'Test::More' => '0.96';
test_requires 'Test::Output'; test_requires 'Test::Output';


perl_version '5.008001'; perl_version '5.008001';
Expand Down
37 changes: 18 additions & 19 deletions lib/Ark/Plugin/Encoding/Unicode.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,38 +2,37 @@ package Ark::Plugin::Encoding::Unicode;
use Ark::Plugin; use Ark::Plugin;
use Scalar::Util 'blessed'; use Scalar::Util 'blessed';


use Encode;

sub prepare_encoding { sub prepare_encoding {
my $self = shift; my $self = shift;
my $req = $self->request; my $req = $self->request;


my $encode = sub { my $encode = sub {
my ($p, $skip) = @_; my ($p) = @_;


if (blessed $p and $p->isa('Hash::MultiValue')) { my $decoded = Hash::MultiValue->new;
return if $skip;
$p->each(sub { $p->each(sub {
utf8::decode($_[1]); $decoded->add( $_[0], decode_utf8($_[1]) );
}); });
}
else { $decoded;
# backward compat
for my $value (values %$p) {
next if ref $value and ref $value ne 'ARRAY';
utf8::decode($_) for ref $value ? @$value : ($value);
}
}
}; };


$encode->($req->query_parameters); $req->env->{'plack.request.query'} = $encode->($req->query_parameters);
$encode->($req->body_parameters); $req->env->{'plack.request.body'} = $encode->($req->body_parameters);
$encode->($req->parameters, 1)
if ($req->env->{'plack.request.merged'}) {
$req->env->{'plack.request.merged'} = $encode->($req->env->{'plack.request.merged'});
}
}; };


sub finalize_encoding { sub finalize_encoding {
my $self = shift; my $self = shift;


my $res = $self->response; 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; 1;
7 changes: 4 additions & 3 deletions t/plugin_unicode.t
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,6 @@
use Test::Base; use strict;
use warnings;
use Test::More;


{ {
package TestApp; package TestApp;
Expand Down Expand Up @@ -27,8 +29,6 @@ use Test::Base;
use Ark::Test 'TestApp', use Ark::Test 'TestApp',
components => [qw/Controller::Root/]; components => [qw/Controller::Root/];


plan 'no_plan';

use URI; use URI;
my $uri = URI->new('/'); my $uri = URI->new('/');
$uri->query_form({ foo => 'テスト' }); $uri->query_form({ foo => 'テスト' });
Expand All @@ -38,3 +38,4 @@ ok($res->is_success, 'request ok');
ok(!utf8::is_utf8($res->content), 'response is binary'); ok(!utf8::is_utf8($res->content), 'response is binary');
is($res->content, 'テスト', 'response content ok'); is($res->content, 'テスト', 'response content ok');


done_testing;

0 comments on commit 76f3da3

Please sign in to comment.