Common/WithRequestWrapper.pm

filter: Statementstmt 100% 53 / 53 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 16 / 16 Podpod 100% 3 / 3 totaltotal 92.3% 85 / 92 CC 8 SCAR 7.8
CC
8
Cov
94%
__ANON__
4.2
request
4.0
_build_ssl_options
2.1
CRAP 2.2
« Common/SyncAgentWrapper.pm ↑ Summary Common.pm »
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
BranchTrueFalseTotal
eval "require IO::Socket::SSL" or return {} 1 0 1
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 // {}
l!l
20
MC/DC0%0/1
$self->ssl_options // {}
$self->ssl_options
Truth table50%1/2
A
A= $self->ssl_options
Aresult
11
00
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
BranchTrueFalseTotal
($kind // '') ne 'http' ? : 1 1 2
Condition60%3/5
$req2 // $request
l!l&&r!l&&!r
020
$kind // ""
l!l
11
MC/DC0%0/2
$req2 // $request
$req2 $request
MC/DC100%1/1
$kind // ""
$kind
Truth table33%1/3
A // B
A= $req2B= $request
ABresult
1X1
011
000
Truth table100%2/2
A
A= $kind
Aresult
11
00
54 request=>($req2//$request),
55 response=>$response,
56 (($kind//'') ne 'http' ? ( more_info => "@_" ) : ()),
57 }),'webservice');
58 },
59 5 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
($request->uri->scheme // '') eq 'https' ? : 2 3 5
Condition100%2/2
$request->uri->scheme // ""
l!l
23
MC/DC100%1/1
$request->uri->scheme // ""
$request->uri->scheme
Truth table100%2/2
A
A= $request->uri->scheme
Aresult
11
00
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__
« Common/SyncAgentWrapper.pm ↑ Summary Common.pm »