lib/Net/Travis/API/UA/Response.pm

filter: Statementstmt 43.8% 25 / 57 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 58.3% 7 / 12 Podpod 100% 4 / 4 totaltotal 33.6% 36 / 107 CC 17 SCAR 34.3
CC
17
Cov
29%
decoded_content
56.0
content_json
56.0
content_type
12.0
CRAP 30.9
↑ Summary lib/Net/Travis/API/UA.pm »
1 1 ▶use 5.010; # _Pulp__5010_qr_m_propagate_properly
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::Travis::API::UA::Response;
7 1 $Net::Travis::API::UA::Response::VERSION = '0.001001';
8 # ABSTRACT: Subclass of HTTP::Tiny::UA::Response for utility methods
9  
10 1 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24 1 ▶use Moo qw( extends has );
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53 1 ▶use Encode qw( FB_CROAK );
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 extends 'HTTP::Tiny::UA::Response';
56  
57  
58  
59  
60  
61  
62  
63  
64  
65 has 'json' => (
66 is => ro =>,
67 lazy => 1,
68 builder => sub {
69 0 ▶ require JSON;
Subroutine _build_json: not called CC=1 SCAR=6.9
70 0 return JSON->new();
71 },
72 1 );
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86 sub content_type {
87 0 ▶ my ($self) = @_;
Subroutine content_type: not called CC=3 SCAR=24.8
Pod documented
88 0 ▶ return unless exists $self->headers->{'content-type'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->headers->{"content-type"} 0 0 0
89 return
90 0 ▶ unless my ($type) = $self->headers->{'content-type'} =~ qr{ \A ( [^/]+ / [^;]+ ) }msx;
Branch: 1 branch
BranchTrueFalseTotal
unless my($type) = $self->headers->{"content-type"} =~ qr" \A ( [^/]+ / [^;]+ ) "msx 0 0 0
91 0 return $type;
92 }
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109 sub content_type_params {
110 0 ▶ my ($self) = @_;
Subroutine content_type_params: not called CC=3 SCAR=24.8
Pod documented
111 0 ▶ return [] unless exists $self->headers->{'content-type'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->headers->{"content-type"} 0 0 0
112 return []
113 0 ▶ unless my (@params) = $self->headers->{'content-type'} =~ qr{ (?:;([^;]+))+ }msx;
Branch: 1 branch
BranchTrueFalseTotal
unless my(@params) = $self->headers->{"content-type"} =~ qr/ (?:;([^;]+))+ /msx 0 0 0
114 0 return [@params];
115 }
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133 sub decoded_content {
134 0 ▶ my ( $self, $force_encoding ) = @_;
Subroutine decoded_content: not called CC=7 SCAR=40.3
Pod documented
135 0 ▶ if ( not $force_encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($force_encoding) 0 0 0
136 0 ▶ return $self->content if not my $type = $self->content_type;
Branch: 1 branch
BranchTrueFalseTotal
unless my $type = $self->content_type 0 0 0
137 0 ▶ return $self->content unless $type =~ qr{ \Atext/ }msx;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ qr" \Atext/ "msx 0 0 0
138 0 for my $param ( @{ $self->content_type_params } ) {
139 0 ▶ if ( $param =~ qr{ \Acharset=(.+)\z }msx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ qr/ \Acharset=(.+)\z /msx) 0 0 0
140 0 $force_encoding = $param;
141 }
142 }
143 0 ▶ return $self->content if not $force_encoding;
Branch: 1 branch
BranchTrueFalseTotal
unless $force_encoding 0 0 0
144 }
145 0 return Encode::decode( $force_encoding, $self->content, Encode::FB_CROAK );
146 }
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165 sub content_json {
166 0 ▶ my ( $self, $force ) = @_;
Subroutine content_json: not called CC=7 SCAR=40.3
Pod documented
167 0 my ($has_force) = ( @_ > 1 );
168  
169 0 my %whitelist = ( 'application/json' => 1 );
170 0 ▶ return unless $has_force or exists $whitelist{ $self->content_type };
Branch: 1 branch
BranchTrueFalseTotal
unless $has_force or exists $whitelist{$self->content_type} 0 0 0
Condition0%0/3
$has_force or exists $whitelist{$self->content_type}
l!l&&r!l&&!r
000
MC/DC0%0/2
$has_force or exists $whitelist{$self->content_type}
$has_force exists $whitelist{$self->content_type}
Truth table0%0/3
A or B
A= $has_forceB= exists $whitelist{$self->content_type}
ABresult
1X1
011
000
171 0 my $charset = 'utf-8';
172 0 ▶ if ( $has_force and defined $force ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_force and defined $force) { } 0 0 0
Condition0%0/3
$has_force and defined $force
!ll&&!rl&&r
000
MC/DC0%0/2
$has_force and defined $force
$has_force defined $force
Truth table0%0/3
A and B
A= $has_forceB= defined $force
ABresult
0X0
100
111
173 0 $charset = $force;
174 }
175 else {
176 0 for my $param ( @{ $self->content_type_params } ) {
177 0 ▶ next unless $param =~ /\Acharset=(.+)\z/msx;
Branch: 1 branch
BranchTrueFalseTotal
unless $param =~ /\Acharset=(.+)\z/msx 0 0 0
178 0 $charset = $1;
179 }
180 }
181 0 return $self->json->utf8(0)->decode( $self->decoded_content($charset) );
182 }
183  
184 1 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
185  
186 1 1;
187  
188 __END__
↑ Summary lib/Net/Travis/API/UA.pm »