blib/lib/Web/Machine/Util/BodyEncoding.pm

filter: Statementstmt 100% 43 / 43 Branchbran 92.8% 13 / 14 Conditioncond 63.6% 7 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 88.7% 79 / 89 CC 12 SCAR 11.7
CC
12
Cov
93%
encode_body
6.1
__ANON__
4.2
__ANON__
3.0
CRAP 3.2
« blib/lib/Web/Machine/FSM/States.pm ↑ Summary blib/lib/Web/Machine.pm »
1 package Web::Machine::Util::BodyEncoding;
2 # ABSTRACT: Module to handle body encoding
3  
4 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 19 our $VERSION = '0.17';
8  
9 19 ▶use Scalar::Util qw/ weaken isweak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use Web::Machine::Util qw[ first pair_key pair_value ];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 19 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 exports => [qw[
15 encode_body_if_set
16 encode_body
17 ]]
18 19 };
19  
20 7 ▶sub encode_body_if_set {
Subroutine encode_body_if_set: called CC=2 SCAR=6.9
Pod documented
21 7 my ($resource, $response) = @_;
22 7 ▶ encode_body( $resource, $response ) if $response->body;
Branch: 1 branch
BranchTrueFalseTotal
if $response->body 2 5 7
23 }
24  
25 44 ▶sub encode_body {
Subroutine encode_body: called CC=6 SCAR=18.0
Pod documented
26 44 my ($resource, $response) = @_;
27  
28 44 my $metadata = $resource->request->env->{'web.machine.context'};
29 44 my $chosen_encoding = $metadata->{'Content-Encoding'};
30 44 my $encoder = $resource->encodings_provided->{ $chosen_encoding };
31  
32 44 my $chosen_charset = $metadata->{'Charset'};
33 44 my $charsetter;
34 44 ▶ if ( $chosen_charset && $resource->charsets_provided ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chosen_charset and $resource->charsets_provided) 14 30 44
Condition66%2/3
$chosen_charset and $resource->charsets_provided
!ll&&!rl&&r
30014
MC/DC50%1/2
$chosen_charset and $resource->charsets_provided
$chosen_charset $resource->charsets_provided
Truth table66%2/3
A and B
A= $chosen_charsetB= $resource->charsets_provided
ABresult
0X0
100
111
35 18 ▶ my $match = first {
Subroutine __ANON__: called CC=4 SCAR=14.3
36 18 ▶ my $name = $_ && ref $_ ? pair_key($_) : $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ && ref $_ ? : 10 8 18
Condition66%2/3
$_ and ref $_
!ll&&!rl&&r
0810
MC/DC50%1/2
$_ and ref $_
$_ ref $_
Truth table66%2/3
A and B
A= $_B= ref $_
ABresult
0X0
100
111
37 18 ▶ $name && $name eq $chosen_charset;
Branch: 1 branch
BranchTrueFalseTotal
$name and $name eq $chosen_charset 18 0 18
38 }
39 14 @{ $resource->charsets_provided };
40  
41 $charsetter
42 = ref $match
43 ? pair_value($match)
44 14 ▶ : sub { Encode::encode( $match, $_[1] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
ref $match ? : 8 6 14
45 }
46  
47 44 ▶ $charsetter ||= sub { $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$charsetter ||= sub { $_[1]; }
l!l&&r!l&&!r
14300
MC/DC0%0/2
$charsetter ||= sub { $_[1]; }
$charsetter sub { $_[1]; }
Truth table66%2/3
A ||= B
A= $charsetterB= sub { $_[1]; }
ABresult
1X1
011
000
48  
49 44 ▶ push @{ $resource->request->env->{'web.machine.content_filters'} ||= [] },
Condition50%1/2
$resource->request->env->{"web.machine.content_filters"} ||= []
l!l
044
MC/DC0%0/1
$resource->request->env->{"web.machine.content_filters"} ||= []
$resource->request->env->{"web.machine.content_filters"}
Truth table50%1/2
A
A= $resource->request->env->{"web.machine.content_filters"}
Aresult
11
00
50 153 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
51 153 my $chunk = shift;
52 153 ▶ weaken $resource unless isweak $resource;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::is_weak($resource) 77 76 153
53 153 ▶ return unless defined $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk 6 147 153
54 147 return $resource->$encoder($resource->$charsetter($chunk));
55 44 };
56 }
57  
58  
59 19 1;
60  
61 __END__
« blib/lib/Web/Machine/FSM/States.pm ↑ Summary blib/lib/Web/Machine.pm »