line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pickles::Plugin::Encode; |
2
|
1
|
|
|
1
|
|
646
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
11
|
use Encode (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
553
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub _decode { |
6
|
6
|
|
|
6
|
|
444
|
my ($hmv, $ie) = @_; |
7
|
6
|
|
|
|
|
100
|
for my $key( $hmv->keys ) { |
8
|
1
|
|
|
|
|
12
|
my @values = map { Encode::decode($ie, $_) } $hmv->get_all( $key ); |
|
1
|
|
|
|
|
17
|
|
9
|
1
|
|
|
|
|
193
|
$hmv->remove( $key ); |
10
|
1
|
|
|
|
|
38
|
$hmv->add( $key => @values ); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _decode_args { |
15
|
3
|
|
|
3
|
|
6
|
my($h, $ie) = @_; |
16
|
3
|
|
|
|
|
4
|
for my $key( keys %{$h} ) { |
|
3
|
|
|
|
|
11
|
|
17
|
2
|
100
|
|
|
|
8
|
if ( ref $h->{$key} eq 'ARRAY' ) { |
18
|
1
|
|
|
|
|
2
|
my @values = map { Encode::decode($ie, $_) } @{$h->{$key}}; |
|
2
|
|
|
|
|
75
|
|
|
1
|
|
|
|
|
4
|
|
19
|
1
|
|
|
|
|
40
|
$h->{$key} = \@values; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
1
|
|
|
|
|
7
|
$h->{$key} = Encode::decode($ie, $h->{$key}); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub install { |
28
|
1
|
|
|
1
|
0
|
2
|
my( $class, $pkg ) = @_; |
29
|
|
|
|
|
|
|
$pkg->add_trigger( init => sub { |
30
|
3
|
|
|
3
|
|
155
|
my $c = shift; |
31
|
3
|
|
|
|
|
18
|
my $config = $c->config->{'Plugin::Encode'}; |
32
|
3
|
|
50
|
|
|
34
|
my $ie = $config->{input_encoding} || 'utf-8'; |
33
|
3
|
|
|
|
|
12
|
_decode( $c->req->query_parameters, $ie ); |
34
|
3
|
|
|
|
|
54
|
_decode( $c->req->body_parameters, $ie ); |
35
|
3
|
|
|
|
|
39
|
_decode_args($c->args, $ie); |
36
|
3
|
|
|
|
|
74
|
delete $c->req->env->{'plack.request.merged'}; # make sure |
37
|
1
|
|
|
|
|
14
|
}); |
38
|
|
|
|
|
|
|
$pkg->add_trigger( pre_finalize => sub { |
39
|
3
|
|
|
3
|
|
152
|
my( $c ) = @_; |
40
|
3
|
50
|
|
|
|
9
|
if ( $c->res->content_type =~ m{^text/} ) { |
41
|
3
|
|
|
|
|
94
|
my $body = $c->res->body; |
42
|
3
|
|
|
|
|
25
|
my $config = $c->config->{'Plugin::Encode'}; |
43
|
3
|
|
50
|
|
|
29
|
my $oe = $config->{output_encoding} || 'utf-8'; |
44
|
3
|
|
|
|
|
9
|
$c->res->content_type( $c->res->content_type. '; charset='. $oe ); |
45
|
3
|
|
|
|
|
118
|
$c->res->body( Encode::encode( $oe, $body ) ); |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
53
|
}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |