AnyUA/Backend/LWP/UserAgent.pm

filter: Statementstmt 88.5% 31 / 35 Branchbran 37.5% 3 / 8 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 75.0% 42 / 56 CC 8 SCAR 21.3
CC
8
Cov
74%
_munge_response
13.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.4
« AnyUA/Backend/Furl.pm ↑ Summary AnyUA/Middleware/ContentLength.pm »
1 package HTTP::AnyUA::Backend::LWP::UserAgent;
2 # ABSTRACT: A unified programming interface for LWP::UserAgent
3  
4  
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.904'; # VERSION
9  
10 2 ▶use parent 'HTTP::AnyUA::Backend';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use HTTP::AnyUA::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 1 ▶sub request {
Subroutine request: called CC=1 SCAR=0.0
Pod documented
16 1 my $self = shift;
17 1 my ($method, $url, $args) = @_;
18  
19 1 my $r = HTTP::AnyUA::Util::native_to_http_request(@_);
20  
21 1 my $ua_resp = $self->ua->request($r);
22  
23 1 return $self->_munge_response($ua_resp, $args->{data_callback});
24 }
25  
26  
27 1 ▶sub _munge_response {
Subroutine _munge_response: called CC=8 SCAR=25.7
28 1 my $self = shift;
29 1 my $ua_resp = shift;
30 1 my $data_cb = shift;
31 1 my $recurse = shift;
32  
33 1 my $resp = {
34 success => !!$ua_resp->is_success,
35 url => $ua_resp->request->uri->as_string,
36 status => $ua_resp->code,
37 reason => $ua_resp->message,
38 headers => HTTP::AnyUA::Util::http_headers_to_native($ua_resp->headers),
39 };
40  
41 1 ▶ $resp->{protocol} = $ua_resp->protocol if $ua_resp->protocol;
Branch: 1 branch
BranchTrueFalseTotal
if $ua_resp->protocol 0 1 1
42  
43 1 ▶ if (!$recurse) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recurse) 1 0 1
44 1 for my $redirect ($ua_resp->redirects) {
45 0 ▶ push @{$resp->{redirects} ||= []}, $self->_munge_response($redirect, undef, 1);
Condition0%0/2
$resp->{"redirects"} ||= []
l!l
00
MC/DC0%0/1
$resp->{"redirects"} ||= []
$resp->{"redirects"}
Truth table0%0/2
A
A= $resp->{"redirects"}
Aresult
11
00
46 }
47 }
48  
49 1 my $content_ref = $ua_resp->content_ref;
50  
51 1 ▶ if (($resp->{headers}{'client-warning'} || '') eq 'Internal response') {
Branch: 2 branches
BranchTrueFalseTotal
if (($resp->{'headers'}{'client-warning'} || '') eq 'Internal response') { } 1 0 1
elsif ($data_cb) { } 0 0 0
Condition50%1/2
$resp->{'headers'}{'client-warning'} || ''
l!l
10
MC/DC0%0/1
$resp->{'headers'}{'client-warning'} || ''
$resp->{'headers'}{'client-warning'}
Truth table50%1/2
A
A= $resp->{'headers'}{'client-warning'}
Aresult
11
00
52 1 HTTP::AnyUA::Util::internal_exception($$content_ref, $resp);
53 }
54 elsif ($data_cb) {
55 0 $data_cb->($$content_ref, $resp);
56 }
57 else {
58 0 $resp->{content} = $$content_ref;
59 }
60  
61 1 return $resp;
62 }
63  
64 2 1;
65  
66 __END__
« AnyUA/Backend/Furl.pm ↑ Summary AnyUA/Middleware/ContentLength.pm »