examples/HTTP/API/Core/Example/TransportAdapters.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 16 / 16 Conditioncond 100% 23 / 23 MC/DCmcdc 100% 13 / 13 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 100% 116 / 116 CC 22 SCAR 12.8
CC
22
Cov
100%
__ANON__
5.0
__ANON__
4.0
mojo_user_agent
4.0
CRAP 3.6
« examples/HTTP/API/Core/Example/Slack.pm ↑ Summary examples/HTTP/API/Core/Example/Cloudflare.pm »
1 package HTTP::API::Core::Example::TransportAdapters;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶sub http_tiny {
Subroutine http_tiny: called CC=3 SCAR=11.0
Pod documented
7 4 my ($http) = @_;
8 4 ▶ die "HTTP::Tiny-compatible object is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $http and $http->can("request") 2 2 4
Condition100%3/3
$http and $http->can("request")
!ll&&!rl&&r
112
MC/DC100%2/2
$http and $http->can("request")
$http $http->can("request")
Truth table100%3/3
A and B
A= $httpB= $http->can("request")
ABresult
0X0
100
111
9 if !$http || !$http->can('request');
10  
11 2 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
12 2 my ($method, $url, $opts) = @_;
13 return $http->request($method, $url, {
14 headers => $opts->{headers} || {},
15 2 ▶ (exists($opts->{content}) ? (content => $opts->{content}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'content'} ? : 1 1 2
Condition100%2/2
$opts->{'headers'} || {}
l!l
11
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
Aresult
11
00
16 });
17 2 };
18 }
19  
20 4 ▶sub lwp_user_agent {
Subroutine lwp_user_agent: called CC=3 SCAR=11.0
Pod documented
21 4 my ($ua) = @_;
22 4 ▶ die "LWP::UserAgent-compatible object is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $ua and $ua->can("request") 2 2 4
Condition100%3/3
$ua and $ua->can("request")
!ll&&!rl&&r
112
MC/DC100%2/2
$ua and $ua->can("request")
$ua $ua->can("request")
Truth table100%3/3
A and B
A= $uaB= $ua->can("request")
ABresult
0X0
100
111
23 if !$ua || !$ua->can('request');
24  
25 2 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
26 2 my ($method, $url, $opts) = @_;
27  
28 2 require HTTP::Request;
29 2 my $request = HTTP::Request->new($method => $url);
30 2 ▶ my $headers = $opts->{headers} || {};
Condition100%2/2
$opts->{'headers'} || {}
l!l
11
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
Aresult
11
00
31 2 $request->header($_ => $headers->{$_}) for keys %$headers;
32 2 ▶ $request->content($opts->{content}) if exists $opts->{content};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"content"} 1 1 2
33  
34 2 my $response = $ua->request($request);
35 2 my %headers = $response->headers->flatten;
36  
37 return {
38 2 status => $response->code,
39 reason => $response->message,
40 headers => \%headers,
41 content => $response->content,
42 };
43 2 };
44 }
45  
46 4 ▶sub mojo_user_agent {
Subroutine mojo_user_agent: called CC=4 SCAR=13.9
Pod documented
47 4 my ($ua) = @_;
48 4 ▶ die "Mojo::UserAgent-compatible object is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $ua and $ua->can("build_tx") and $ua->can("start") 3 1 4
Condition100%6/6
$ua and $ua->can("build_tx") and $ua->can("start")
!ll&&!rl&&r
211
$ua and $ua->can("build_tx")
!ll&&!rl&&r
112
MC/DC100%3/3
$ua and $ua->can("build_tx") and $ua->can("start")
$ua $ua->can("build_tx") $ua->can("start")
Truth table100%4/4
A and B and C
A= $uaB= $ua->can("build_tx")C= $ua->can("start")
ABCresult
0XX0
10X0
1100
1111
49 if !$ua || !$ua->can('build_tx') || !$ua->can('start');
50  
51 2 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
52 2 my ($method, $url, $opts) = @_;
53 2 ▶ my $headers = $opts->{headers} || {};
Condition100%2/2
$opts->{'headers'} || {}
l!l
11
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
Aresult
11
00
54  
55 2 my $tx = $ua->build_tx($method => $url => $headers);
56 2 ▶ $tx->req->body($opts->{content}) if exists $opts->{content};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"content"} 1 1 2
57 2 my $result = $ua->start($tx)->result;
58  
59 2 my %response_headers;
60 2 for my $name (@{ $result->headers->names }) {
61 4 $response_headers{$name} = $result->headers->header($name);
62 }
63  
64 return {
65 2 status => $result->code,
66 reason => $result->message,
67 headers => \%response_headers,
68 content => $result->body,
69 };
70 1 };
71 }
72  
73 3 ▶sub furl {
Subroutine furl: called CC=3 SCAR=11.0
Pod documented
74 3 my ($furl) = @_;
75 3 ▶ die "Furl-compatible object is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $furl and $furl->can("request") 2 1 3
Condition100%3/3
$furl and $furl->can("request")
!ll&&!rl&&r
111
MC/DC100%2/2
$furl and $furl->can("request")
$furl $furl->can("request")
Truth table100%3/3
A and B
A= $furlB= $furl->can("request")
ABresult
0X0
100
111
76 if !$furl || !$furl->can('request');
77  
78 2 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
79 2 my ($method, $url, $opts) = @_;
80 2 ▶ my $headers = $opts->{headers} || {};
Condition100%2/2
$opts->{'headers'} || {}
l!l
11
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
Aresult
11
00
81 2 my @headers;
82 2 push @headers, $_ => $headers->{$_} for keys %$headers;
83  
84 my $response = $furl->request(
85 method => $method,
86 url => $url,
87 headers => \@headers,
88 2 ▶ (exists($opts->{content}) ? (content => $opts->{content}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'content'} ? : 1 1 2
89 );
90  
91 2 my %response_headers;
92 2 my $response_header = $response->headers;
93 2 for my $name ($response_header->header_field_names) {
94 4 $response_headers{$name} = $response_header->header($name);
95 }
96  
97 return {
98 2 status => $response->code,
99 reason => $response->message,
100 headers => \%response_headers,
101 content => $response->content,
102 };
103 1 };
104 }
105  
106 1 1;
107  
108 __END__
« examples/HTTP/API/Core/Example/Slack.pm ↑ Summary examples/HTTP/API/Core/Example/Cloudflare.pm »