| 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
| |||||||||||
| 48 | 0 | ▶ | $copy{$k} = ref($v) eq 'ARRAY' ? [@$v] : $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 2 | 1; | |||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | # vim: ts=4 sts=4 sw=4 et: | ||||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||