| 1 | package Catmandu::Importer; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 35 | our $VERSION = '1.2025'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Catmandu::Util qw(io is_value is_string is_array_ref is_hash_ref); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Catmandu::Util::Path qw(as_path); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use HTTP::Request (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 35 | ▶ | use URI (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 35 | ▶ | use URI::Template (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 35 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 35 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 35 | with 'Catmandu::Logger'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 35 | with 'Catmandu::Iterable'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 35 | with 'Catmandu::IterableOnce'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 35 | with 'Catmandu::Fixable'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 35 | with 'Catmandu::Serializer'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 83 | ▶ | around generator => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 83 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 83 | my $generator = $orig->($self); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 83 | ▶ | if (my $fixer = $self->_fixer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | $generator = $fixer->fix($generator); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 83 | ▶ | if (defined(my $path = $self->data_path)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | my $getter = as_path($path)->getter; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | state @buf; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | return shift @buf if @buf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | @buf = @{$getter->($generator->() // return)}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
&$generator() // (return)
MC/DC100%1/1
&$generator() // (return)
&$generator()
Truth table100%2/2
A
A= &$generator()
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 81 | $generator; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 35 | }; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 35 | has file => (is => 'lazy', init_arg => undef); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 35 | has _file_template => | |||||||||||||||||||||||||||||||||||||||||
| 48 | (is => 'ro', predicate => 'has_file', init_arg => 'file'); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 35 | has variables => (is => 'ro', predicate => 1); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 35 | has fh => (is => 'ro', lazy => 1, builder => 1); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 35 | has encoding => (is => 'ro', builder => 1); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 35 | has data_path => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 35 | has user_agent => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 35 | has http_method => (is => 'lazy'); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 35 | has http_headers => (is => 'lazy'); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 35 | has http_agent => (is => 'ro', predicate => 1); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 35 | has http_max_redirect => (is => 'ro', predicate => 1); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 108 | ▶ | has http_timeout => (is => 'ro', default => sub {180}); # LWP default | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 108 | ▶ | has http_verify_hostname => (is => 'ro', default => sub {1}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 35 | has http_retry => (is => 'ro', predicate => 1); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 35 | has http_timing => (is => 'ro', predicate => 1); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 35 | has http_body => (is => 'ro', predicate => 1); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 35 | has _http_client => ( | |||||||||||||||||||||||||||||||||||||||||
| 64 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | builder => '_build_http_client', | ||||||||||||||||||||||||||||||||||||||||||
| 67 | init_arg => 'user_agent' | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 35 | has _http_timing_tries => (is => 'lazy'); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 35 | has ignore_404 => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 100 | ▶ | sub _build_encoding { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_encoding: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 100 | ':utf8'; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 67 | ▶ | sub _build_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_file: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 67 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 67 | ▶ | return \*STDIN unless $self->has_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 67 | my $file = $self->_file_template; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 67 | ▶ | if (is_string($file) && $self->has_variables) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_string($file) and $self->has_variables
MC/DC100%2/2
is_string($file) and $self->has_variables
is_string($file)
$self->has_variables
Truth table100%3/3
A and B
A= is_string($file)B= $self->has_variables
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | my $template = URI::Template->new($file); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | my $vars = $self->variables; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | ▶ | if (is_value($vars)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | $vars = [split ',', $vars]; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | if (is_array_ref($vars)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | my @keys = $template->variables; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | my @vals = @$vars; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | $vars = {}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | $vars->{shift @keys} = shift @vals while @keys && @vals; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@keys and @vals
MC/DC50%1/2
@keys and @vals
@keys
@vals
Truth table66%2/3
A and B
A= @keysB= @vals
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | $file = $template->process_to_string(%$vars); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 67 | ▶ | if (is_string($file) && $file !~ m!^https?://! && !-r $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
is_string($file) and not $file =~ m[^https?://] and not -r $file
is_string($file) and not $file =~ m[^https?://]
MC/DC100%3/3
is_string($file) and not $file =~ m[^https?://] and not -r $file
is_string($file)
not $file =~ m[^https?://]
not -r $file
Truth table100%4/4
A and not(B) and not(C)
A= is_string($file)B= not $file =~ m[^https?://]C= not -r $file
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | Catmandu::BadArg->throw("file '$file' doesn't exist"); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 66 | $file; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 64 | ▶ | sub _build_fh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_fh: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 64 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 64 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # get remote content | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 63 | ▶ | if (is_string($file) && $file =~ m!^https?://!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_string($file) and $file =~ m[^https?://]
MC/DC100%2/2
is_string($file) and $file =~ m[^https?://]
is_string($file)
$file =~ m[^https?://]
Truth table100%3/3
A and B
A= is_string($file)B= $file =~ m[^https?://]
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | my $body; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 13 | ▶ | if ($self->has_http_body) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | $body = $self->http_body; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if (ref $body) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $body = $self->serialize($body); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | if ($self->has_variables) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | my $vars = $self->variables; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | if (is_hash_ref($vars)) { # named variables | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | for my $key (keys %$vars) { | |||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | my $var = $vars->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $body =~ s/{$key}/$var/; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | else { # positional variables | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | if (is_value($vars)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | $vars = [split ',', $vars]; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | for my $var (@$vars) { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | $body =~ s/{\w+}/$var/; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 13 | my $content = $self->_http_request( | |||||||||||||||||||||||||||||||||||||||||
| 135 | $self->http_method, $file, $self->http_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | $body, $self->_http_timing_tries, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | return io(\$content, mode => 'r', binmode => $_[0]->encoding); | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 50 | io($file, mode => 'r', binmode => $_[0]->encoding); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 13 | ▶ | sub _build_http_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_http_headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 13 | []; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 10 | ▶ | sub _build_http_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_http_method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 10 | 'GET'; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 13 | ▶ | sub _build__http_timing_tries { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__http_timing_tries: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 13 | ▶ | if ($self->has_http_timing) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my @timing_tries = $self->http_timing =~ /(\d+(?:\.\d+)*)/g; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | return \@timing_tries; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | elsif ($self->has_http_retry) { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | my @timing_tries = (1) x $self->http_retry; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | return \@timing_tries; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | sub _build_http_client { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_http_client: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | $ua->timeout($self->http_timeout); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | $ua->agent($self->http_agent) if $self->has_http_agent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 2 | ▶ | $ua->max_redirect($self->http_max_redirect) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | if $self->has_http_max_redirect; | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | $ua->ssl_opts(verify_hostname => $self->http_verify_hostname); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | $ua->protocols_allowed([qw(http https)]); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | $ua->env_proxy; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | $ua; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 13 | ▶ | sub _http_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_http_request: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 13 | my ($self, $method, $url, $headers, $body, $timing_tries) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 13 | my $client = $self->_http_client; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 13 | ▶ | my $req = HTTP::Request->new($method, $url, $headers || []); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$headers || []
MC/DC0%0/1
$headers || []
$headers
Truth table50%1/2
A
A= $headers
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 13 | ▶ | $req->content($body) if defined $body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 13 | my $res = $client->request($req); | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 13 | ▶ | if ($res->code =~ /^408|500|502|503|504$/ && $timing_tries) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$res->code =~ /^408|500|502|503|504$/ and $timing_tries
MC/DC100%2/2
$res->code =~ /^408|500|502|503|504$/ and $timing_tries
$res->code =~ /^408|500|502|503|504$/
$timing_tries
Truth table100%3/3
A and B
A= $res->code =~ /^408|500|502|503|504$/B= $timing_tries
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | my @tries = @$timing_tries; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | ▶ | while (my $sleep = shift @tries) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 6 | sleep $sleep; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 6 | $res = $client->request($req->clone); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 6 | ▶ | last if $res->code !~ /^408|500|502|503|504$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 13 | my $res_body = $res->decoded_content; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 13 | ▶ | unless ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | my $res_headers = []; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | for my $header ($res->header_field_names) { | |||||||||||||||||||||||||||||||||||||||||
| 204 | 18 | my $val = $res->header($header); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 18 | push @$res_headers, $header, $val; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | Catmandu::HTTPError->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | code => $res->code, | |||||||||||||||||||||||||||||||||||||||||
| 210 | message => $res->status_line, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | url => $url, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | request_headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | request_body => $body, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | response_headers => $res_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 216 | response_body => $res_body, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | $res_body; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub readline { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | warnings::warnif("deprecated", | |||||||||||||||||||||||||||||||||||||||||
| 226 | "readline is deprecated, fh->getline instead"); | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $_[0]->fh->getline; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub readall { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readall: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | warnings::warnif("deprecated", | |||||||||||||||||||||||||||||||||||||||||
| 232 | "readall is deprecated, join('',fh->getlines) instead"); | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | join '', $_[0]->fh->getlines; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 35 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | __END__ | ||||||||||||||||||||||||||||||||||||||||||