| 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
Condition100%3/3
$http and $http->can("request")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$opts->{'headers'} || {}
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$ua and $ua->can("request")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | $request->header($_ => $headers->{$_}) for keys %$headers; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | $request->content($opts->{content}) if exists $opts->{content}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$ua and $ua->can("build_tx") and $ua->can("start")
$ua and $ua->can("build_tx")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$furl and $furl->can("request")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC100%1/1
$opts->{'headers'} || {}
$opts->{'headers'}
Truth table100%2/2
A
A= $opts->{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||