| 1 | package Pickles::Plugin::Encode; | ||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use Encode (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 6 | ▶ | sub _decode { | ||||||||||
|
Subroutine
_decode: called CC=2 SCAR=6.9
| |||||||||||||
| 6 | 6 | my ($hmv, $ie) = @_; | |||||||||||
| 7 | 6 | for my $key( $hmv->keys ) { | |||||||||||
| 8 | 1 | my @values = map { Encode::decode($ie, $_) } $hmv->get_all( $key ); | |||||||||||
| 9 | 1 | $hmv->remove( $key ); | |||||||||||
| 10 | 1 | $hmv->add( $key => @values ); | |||||||||||
| 11 | } | ||||||||||||
| 12 | } | ||||||||||||
| 13 | |||||||||||||
| 14 | 3 | ▶ | sub _decode_args { | ||||||||||
|
Subroutine
_decode_args: called CC=3 SCAR=11.0
| |||||||||||||
| 15 | 3 | my($h, $ie) = @_; | |||||||||||
| 16 | 3 | for my $key( keys %{$h} ) { | |||||||||||
| 17 | 2 | ▶ | if ( ref $h->{$key} eq 'ARRAY' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | 1 | my @values = map { Encode::decode($ie, $_) } @{$h->{$key}}; | |||||||||||
| 19 | 1 | $h->{$key} = \@values; | |||||||||||
| 20 | } | ||||||||||||
| 21 | else { | ||||||||||||
| 22 | 1 | $h->{$key} = Encode::decode($ie, $h->{$key}); | |||||||||||
| 23 | } | ||||||||||||
| 24 | } | ||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 1 | ▶ | sub install { | ||||||||||
|
Subroutine
install: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 28 | 1 | my( $class, $pkg ) = @_; | |||||||||||
| 29 | 3 | ▶ | $pkg->add_trigger( init => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||
| 30 | 3 | my $c = shift; | |||||||||||
| 31 | 3 | my $config = $c->config->{'Plugin::Encode'}; | |||||||||||
| 32 | 3 | ▶ | my $ie = $config->{input_encoding} || 'utf-8'; | ||||||||||
|
Condition50%1/2
$config->{'input_encoding'} || 'utf-8'
MC/DC0%0/1
$config->{'input_encoding'} || 'utf-8'
$config->{'input_encoding'}
Truth table50%1/2
A
A= $config->{'input_encoding'}
| |||||||||||||
| 33 | 3 | _decode( $c->req->query_parameters, $ie ); | |||||||||||
| 34 | 3 | _decode( $c->req->body_parameters, $ie ); | |||||||||||
| 35 | 3 | _decode_args($c->args, $ie); | |||||||||||
| 36 | 3 | delete $c->req->env->{'plack.request.merged'}; # make sure | |||||||||||
| 37 | 1 | }); | |||||||||||
| 38 | 3 | ▶ | $pkg->add_trigger( pre_finalize => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||
| 39 | 3 | my( $c ) = @_; | |||||||||||
| 40 | 3 | ▶ | if ( $c->res->content_type =~ m{^text/} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 3 | my $body = $c->res->body; | |||||||||||
| 42 | 3 | my $config = $c->config->{'Plugin::Encode'}; | |||||||||||
| 43 | 3 | ▶ | my $oe = $config->{output_encoding} || 'utf-8'; | ||||||||||
|
Condition50%1/2
$config->{'output_encoding'} || 'utf-8'
MC/DC0%0/1
$config->{'output_encoding'} || 'utf-8'
$config->{'output_encoding'}
Truth table50%1/2
A
A= $config->{'output_encoding'}
| |||||||||||||
| 44 | 3 | $c->res->content_type( $c->res->content_type. '; charset='. $oe ); | |||||||||||
| 45 | 3 | $c->res->body( Encode::encode( $oe, $body ) ); | |||||||||||
| 46 | } | ||||||||||||
| 47 | 1 | }); | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 1 | 1; | |||||||||||
| 51 | |||||||||||||
| 52 | __END__ | ||||||||||||