| 1 | package UserAgent::Any::Fake::Response; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.036; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use UserAgent::Any::Impl::Helper 'params_to_hash'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | our $VERSION = 0.01; | |||||||||
| 12 | |||||||||||
| 13 | 1 | extends 'UserAgent::Any::Response'; | |||||||||
| 14 | 1 | with 'UserAgent::Any::Response::Impl'; | |||||||||
| 15 | |||||||||||
| 16 | 1 | has '+_impl' => (required => 0,); | |||||||||
| 17 | |||||||||||
| 18 | 1 | has '+res' => (required => 0,); | |||||||||
| 19 | |||||||||||
| 20 | 1 | has [qw(status_code status_text content _headers)] => (is => 'rw',); | |||||||||
| 21 | |||||||||||
| 22 | 1 | Readonly my $HTTP_STATUS_CODE_SUCCESS_MIN => 200; | |||||||||
| 23 | 1 | Readonly my $HTTP_STATUS_CODE_SUCCESS_MAX => 299; | |||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | sub success ($self) { | ||||||||
|
Subroutine
success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 2 | return $HTTP_STATUS_CODE_SUCCESS_MIN <= $self->status_code <= $HTTP_STATUS_CODE_SUCCESS_MAX; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | sub raw_content ($self, $content = undef) { | ||||||||
|
Subroutine
raw_content: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||
| 30 | 1 | ▶ | return $self->content($content) if defined $content; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | return $self->content; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 6 | ▶ | sub header ($self, $k, $val = undef) { | ||||||||
|
Subroutine
header: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 35 | 6 | ▶ | if (defined $val) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | $self->_headers->{$k} = $val; | |||||||||
| 37 | 1 | return; | |||||||||
| 38 | } | ||||||||||
| 39 | 5 | my $v = $self->_headers->{$k}; | |||||||||
| 40 | 5 | ▶ | return unless defined $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 5 | ▶ | return $v unless ref($v); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 4 | ▶ | return @{$v} if wantarray; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 1 | return join(',', @{$v}); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 2 | ▶ | sub headers ($self, @headers) { | ||||||||
|
Subroutine
headers: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 47 | 2 | ▶ | if (@headers) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 1 | $self->_headers(params_to_hash(@headers)); | |||||||||
| 49 | 1 | return; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | my @all_headers; | |||||||||
| 53 | 1 | for my $k (sort keys %{$self->_headers}) { | |||||||||
| 54 | 3 | push @all_headers, map { ($k, $_) } $self->header($k); | |||||||||
| 55 | } | ||||||||||
| 56 | 1 | return @all_headers; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1 | 1; | |||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||