| 1 | package Net::Async::Webservice::Common::SyncAgentWrapper; | ||||||||||||||||||||||||||||
| 2 | 2 | $Net::Async::Webservice::Common::SyncAgentWrapper::VERSION = '1.0.2'; | |||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||
| 4 | 2 | $Net::Async::Webservice::Common::SyncAgentWrapper::DIST = 'Net-Async-Webservice-Common'; | |||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Net::Async::Webservice::Common::Types 'SyncUserAgent'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use HTTP::Request::Common qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ABSTRACT: minimal wrapper to adapt a sync UA | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | has ua => ( | |||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | isa => SyncUserAgent, | ||||||||||||||||||||||||||||
| 21 | required => 1, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | sub do_request { | ||||||||||||||||||||||||||
|
Subroutine
do_request: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 5 | my ($self,%args) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | if( my $uri = delete $args{uri} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 1 | %args = $self->_make_request( $uri, %args ); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | my $request = $args{request}; | |||||||||||||||||||||||||||
| 33 | 5 | my $fail = $args{fail_on_error}; | |||||||||||||||||||||||||||
| 34 | 5 | ▶ | my %ssl = map { m/^SSL_/ ? ( $_ => $args{$_} ) : () } keys %args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 5 | ▶ | if ($self->ua->can('ssl_opts') && %ssl) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->ua->can("ssl_opts") and %ssl
MC/DC50%1/2
$self->ua->can("ssl_opts") and %ssl
$self->ua->can("ssl_opts")
%ssl
Truth table66%2/3
A and B
A= $self->ua->can("ssl_opts")B= %ssl
| |||||||||||||||||||||||||||||
| 36 | 1 | $self->ua->ssl_opts(%ssl); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | my $response = $self->ua->request($request); | |||||||||||||||||||||||||||
| 40 | 5 | ▶ | if ($fail && ! $response->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fail and not $response->is_success
MC/DC50%1/2
$fail and not $response->is_success
$fail
not $response->is_success
Truth table66%2/3
A and not(B)
A= $failB= not $response->is_success
| |||||||||||||||||||||||||||||
| 41 | 1 | return Future->new->fail($response->status_line,'http',$response,$request); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 4 | return Future->wrap($response); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub _make_request | ||||||||||||||||||||||||||||
| 47 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_make_request: called CC=14 SCAR=32.8
| |||||||||||||||||||||||||||||
| 48 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 1 | my ( $uri, %args ) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | if( !ref $uri ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 1 | $uri = URI->new( $uri ); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | ▶ | elsif( blessed $uri and !$uri->isa( "URI" ) ) { | |||||||||||||||||||||||||||
|
Condition0%0/3
builtin::blessed($uri) and not $uri->isa("URI")
MC/DC0%0/2
builtin::blessed($uri) and not $uri->isa("URI")
builtin::blessed($uri)
not $uri->isa("URI")
Truth table0%0/3
A and not(B)
A= builtin::blessed($uri)B= not $uri->isa("URI")
| |||||||||||||||||||||||||||||
| 55 | 0 | croak "Expected 'uri' as a URI reference"; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | my $method = delete $args{method} || "GET"; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'method'} || 'GET'
MC/DC0%0/1
delete $args{'method'} || 'GET'
delete $args{'method'}
Truth table50%1/2
A
A= delete $args{'method'}
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | $args{host} = $uri->host; | |||||||||||||||||||||||||||
| 61 | 1 | $args{port} = $uri->port; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | my $request; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | if( $method eq "POST" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | defined $args{content} or croak "Expected 'content' with POST method"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Lack of content_type didn't used to be a failure condition: | ||||||||||||||||||||||||||||
| 69 | ref $args{content} or defined $args{content_type} or | ||||||||||||||||||||||||||||
| 70 | 1 | ▶ | carp "No 'content_type' was given with 'content'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args{"content"} or defined $args{"content_type"}
MC/DC0%0/2
ref $args{"content"} or defined $args{"content_type"}
ref $args{"content"}
defined $args{"content_type"}
Truth table33%1/3
A or B
A= ref $args{"content"}B= defined $args{"content_type"}
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # This will automatically encode a form for us | ||||||||||||||||||||||||||||
| 73 | 1 | $request = HTTP::Request::Common::POST( $uri, Content => $args{content}, Content_Type => $args{content_type} ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||
| 76 | 0 | $request = HTTP::Request->new( $method, $uri ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | $request->protocol( "HTTP/1.1" ); | |||||||||||||||||||||||||||
| 80 | 1 | $request->header( Host => $uri->host ); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | my ( $user, $pass ); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | if( defined $uri->userinfo ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 85 | 0 | ( $user, $pass ) = split( m/:/, $uri->userinfo, 2 ); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | ▶ | elsif( defined $args{user} and defined $args{pass} ) { | |||||||||||||||||||||||||||
|
Condition33%1/3
defined $args{"user"} and defined $args{"pass"}
MC/DC0%0/2
defined $args{"user"} and defined $args{"pass"}
defined $args{"user"}
defined $args{"pass"}
Truth table33%1/3
A and B
A= defined $args{"user"}B= defined $args{"pass"}
| |||||||||||||||||||||||||||||
| 88 | 1 | $user = $args{user}; | |||||||||||||||||||||||||||
| 89 | 1 | $pass = $args{pass}; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | ▶ | if( defined $user and defined $pass ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $user and defined $pass
MC/DC0%0/2
defined $user and defined $pass
defined $user
defined $pass
Truth table33%1/3
A and B
A= defined $userB= defined $pass
| |||||||||||||||||||||||||||||
| 93 | 1 | $request->authorization_basic( $user, $pass ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | $args{request} = $request; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | return %args; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub GET { | ||||||||||||||||||||||||||
|
Subroutine
GET: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my ($self, $uri, @args) = @_; | |||||||||||||||||||||||||||
| 104 | 0 | return $self->do_request( method => "GET", uri => $uri, @args ); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub HEAD { | ||||||||||||||||||||||||||
|
Subroutine
HEAD: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my ($self, $uri, @args) = @_; | |||||||||||||||||||||||||||
| 109 | 0 | return $self->do_request( method => "HEAD", uri => $uri, @args ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub POST { | ||||||||||||||||||||||||||
|
Subroutine
POST: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $uri, $content, @args) = @_; | |||||||||||||||||||||||||||
| 114 | 0 | return $self->do_request( method => "POST", uri => $uri, content => $content, @args ); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||