UA/Response.pm

filter: Statementstmt 75.0% 18 / 24 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 67.5% 25 / 37 CC 4 SCAR 15.9
CC
4
Cov
63%
headers
12.0
header
2.0
BEGIN
1.0
CRAP 4.9
↑ Summary UA.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package HTTP::Tiny::UA::Response;
5 # ABSTRACT: Wrap HTTP::Tiny response as objects with accessors
6  
7 2 our $VERSION = '0.006';
8  
9 # Declare custom accessor before Class::Tiny loads
10 2 ▶use subs 'headers';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Class::Tiny 1.000 qw( success url status reason content protocol headers );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #pod =attr success
15 #pod
16 #pod =attr url
17 #pod
18 #pod =attr protocol
19 #pod
20 #pod =attr status
21 #pod
22 #pod =attr reason
23 #pod
24 #pod =attr content
25 #pod
26 #pod =attr headers
27 #pod
28 #pod =method header
29 #pod
30 #pod $response->header( "Content-Length" );
31 #pod
32 #pod Return a header out of the headers hash. The field is case-insensitive. If
33 #pod the header was repeated, the value returned will be an array reference.
34 #pod Otherwise it will be a scalar value.
35 #pod
36 #pod =cut
37  
38 # Don't return the original hash reference because the caller could
39 # alter that referred-to hash, which in turn would alter this object's
40 # internals, which we almost certainly do not want!
41 0 ▶sub headers {
Subroutine headers: not called CC=3 SCAR=24.8
42 0 my ($self) = @_;
43  
44 0 my $headers = $self->{headers};
45 0 my %copy;
46  
47 0 ▶ while ( my ( $k, $v ) = each %$headers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$headers) 0 0 0
48 0 ▶ $copy{$k} = ref($v) eq 'ARRAY' ? [@$v] : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
49 }
50  
51 0 return \%copy;
52 }
53  
54 1 ▶sub header {
Subroutine header: called CC=2 SCAR=7.0
Pod documented
55 1 my ( $self, $field ) = @_;
56  
57 # NB: lc() can potentially use non-English (e.g., Turkish)
58 # lowercasing logic, which we very likely do not want here.
59 1 $field =~ tr/A-Z/a-z/;
60  
61 # We don't return the original array reference for the same reason
62 # why headers() doesn't return the original hash reference.
63 1 my $hdr = $self->{headers}{$field};
64  
65 1 ▶ return ref($hdr) eq 'ARRAY' ? [@$hdr] : $hdr;
Branch: 1 branch
BranchTrueFalseTotal
ref $hdr eq 'ARRAY' ? : 0 1 1
66 }
67  
68 2 1;
69  
70  
71 # vim: ts=4 sts=4 sw=4 et:
72  
73 __END__
↑ Summary UA.pm »