| 1 | package Net::Async::Webservice::Common::WithRequestWrapper; | ||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $Net::Async::Webservice::Common::WithRequestWrapper::VERSION = '1.0.2'; | |||||||||||||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||||||||||||
| 4 | 1 | $Net::Async::Webservice::Common::WithRequestWrapper::DIST = 'Net-Async-Webservice-Common'; | |||||||||||||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Types::Standard qw(Object HashRef Str); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Types::URI qw(Uri); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Type::Params qw(compile); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Net::Async::Webservice::Common::Types qw(HTTPRequest); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Net::Async::Webservice::Common::Exception; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | # ABSTRACT: helper methods to perform HTTP request | ||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 1 | requires 'user_agent'; | |||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 1 | has ssl_options => ( | |||||||||||||||||||||||||||||||||||||
| 24 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 25 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub _build_ssl_options { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_ssl_options: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||
| 28 | # this is to work around an issue with IO::Async::SSL, see | ||||||||||||||||||||||||||||||||||||||
| 29 | # https://rt.cpan.org/Ticket/Display.html?id=96474 | ||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | eval "require IO::Socket::SSL" or return {}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 31 | 1 | return { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER() } | |||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | sub request { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 36 | 5 | state $argcheck = compile( Object, HTTPRequest ); | |||||||||||||||||||||||||||||||||||||
| 37 | 5 | my ($self, $request) = $argcheck->(@_); | |||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | my $response_future = $self->user_agent->do_request( | ||||||||||||||||||||||||||||||||||||||
| 40 | request => $request, | ||||||||||||||||||||||||||||||||||||||
| 41 | fail_on_error => 1, | ||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | (($request->uri->scheme//'') eq 'https' ? %{ $self->ssl_options // {} } : ()), | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->ssl_options // {}
MC/DC0%0/1
$self->ssl_options // {}
$self->ssl_options
Truth table50%1/2
A
A= $self->ssl_options
| |||||||||||||||||||||||||||||||||||||||
| 43 | )->transform( | ||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | done => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my ($response) = @_; | |||||||||||||||||||||||||||||||||||||
| 46 | 3 | return $response->decoded_content( | |||||||||||||||||||||||||||||||||||||
| 47 | default_charset => 'utf-8', | ||||||||||||||||||||||||||||||||||||||
| 48 | raise_error => 1, | ||||||||||||||||||||||||||||||||||||||
| 49 | ) | ||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | fail => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||
| 52 | 2 | my ($exception,$kind,$response,$req2) = @_; | |||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | return (Net::Async::Webservice::Common::Exception::HTTPError->new({ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$req2 // $request
$kind // ""
MC/DC0%0/2
$req2 // $request
$req2
$request
MC/DC100%1/1
$kind // ""
$kind
Truth table33%1/3
A // B
A= $req2B= $request
Truth table100%2/2
A
A= $kind
| |||||||||||||||||||||||||||||||||||||||
| 54 | request=>($req2//$request), | ||||||||||||||||||||||||||||||||||||||
| 55 | response=>$response, | ||||||||||||||||||||||||||||||||||||||
| 56 | (($kind//'') ne 'http' ? ( more_info => "@_" ) : ()), | ||||||||||||||||||||||||||||||||||||||
| 57 | }),'webservice'); | ||||||||||||||||||||||||||||||||||||||
| 58 | }, | ||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$request->uri->scheme // ""
MC/DC100%1/1
$request->uri->scheme // ""
$request->uri->scheme
Truth table100%2/2
A
A= $request->uri->scheme
| |||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub post { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
post: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 64 | 1 | state $argcheck = compile( Object, Uri, Str ); | |||||||||||||||||||||||||||||||||||||
| 65 | 1 | my ($self, $url, $body) = $argcheck->(@_); | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $request = HTTP::Request->new( | |||||||||||||||||||||||||||||||||||||
| 68 | POST => $url, | ||||||||||||||||||||||||||||||||||||||
| 69 | [], encode('utf-8',$body), | ||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||
| 71 | 1 | return $self->request($request); | |||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 76 | 3 | state $argcheck = compile( Object, Uri ); | |||||||||||||||||||||||||||||||||||||
| 77 | 3 | my ($self, $url) = $argcheck->(@_); | |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 3 | my $request = HTTP::Request->new( | |||||||||||||||||||||||||||||||||||||
| 80 | GET => $url, | ||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||
| 82 | 3 | return $self->request($request); | |||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||||||||||||