File Coverage

blib/lib/HTTP/Tiny/UA/Response.pm
Criterion Covered Total %
statement 16 22 72.7
branch 1 4 25.0
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 23 33 69.7


line stmt bran cond sub pod time code
1 2     2   14 use strict;
  2         5  
  2         62  
2 2     2   10 use warnings;
  2         4  
  2         98  
3              
4             package HTTP::Tiny::UA::Response;
5             # ABSTRACT: Wrap HTTP::Tiny response as objects with accessors
6              
7             our $VERSION = '0.006';
8              
9             # Declare custom accessor before Class::Tiny loads
10 2     2   1060 use subs 'headers';
  2         47  
  2         11  
11              
12 2     2   1047 use Class::Tiny 1.000 qw( success url status reason content protocol headers );
  2         3437  
  2         42  
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             sub headers {
42 0     0   0 my ($self) = @_;
43              
44 0         0 my $headers = $self->{headers};
45 0         0 my %copy;
46              
47 0         0 while ( my ( $k, $v ) = each %$headers ) {
48 0 0       0 $copy{$k} = ref($v) eq 'ARRAY' ? [@$v] : $v;
49             }
50              
51 0         0 return \%copy;
52             }
53              
54             sub header {
55 1     1 1 3525 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         5 $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         3 my $hdr = $self->{headers}{$field};
64              
65 1 50       9 return ref($hdr) eq 'ARRAY' ? [@$hdr] : $hdr;
66             }
67              
68             1;
69              
70              
71             # vim: ts=4 sts=4 sw=4 et:
72              
73             __END__