| 1 | package WebService::Async::UserAgent::NaHTTP; | ||||||||||||||||||||||||||||||||
| 2 | 1 | $WebService::Async::UserAgent::NaHTTP::VERSION = '0.004'; | |||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use parent qw(WebService::Async::UserAgent); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | WebService::Async::UserAgent::NaHTTP - make requests using L<Net::Async::HTTP> | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | version 0.004 | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | Provides a L</request> method which will use L<Net::Async::HTTP> to make | ||||||||||||||||||||||||||||||||
| 19 | requests and return a L<Future> containing the result. Used internally by | ||||||||||||||||||||||||||||||||
| 20 | L<WebService::Async::UserAgent>. | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Future; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Net::Async::HTTP; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | =head2 request | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | Issues the request. Expects a single L<HTTP::Request> object, | ||||||||||||||||||||||||||||||||
| 31 | and returns a L<Future> which will resolve to the decoded | ||||||||||||||||||||||||||||||||
| 32 | response content on success, or the failure reason on failure. | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | sub request { | ||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my ($self, $req, %args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=9 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 38 | 1 | my $host = delete $args{host}; | |||||||||||||||||||||||||||||||
| 39 | 1 | my $port = delete $args{port}; | |||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | unless(defined($host) && defined($port)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $host and defined $port
MC/DC0%0/2
defined $host and defined $port
defined $host
defined $port
Truth table33%1/3
A and B
A= defined $hostB= defined $port
| |||||||||||||||||||||||||||||||||
| 41 | 1 | my ($h, $p) = split /:/, '' . $req->uri->host_port; | |||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | $host //= $h; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$host //= $h
MC/DC0%0/2
$host //= $h
$host
$h
Truth table33%1/3
A //= B
A= $hostB= $h
| |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | $port //= $p; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$port //= $p
MC/DC0%0/2
$port //= $p
$port
$p
Truth table33%1/3
A //= B
A= $portB= $p
| |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | my $ssl = delete($args{ssl}) // ($req->uri->scheme eq 'https'); | ||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{"ssl"} // $req->uri->scheme eq "https"
MC/DC0%0/2
delete $args{"ssl"} // $req->uri->scheme eq "https"
delete $args{"ssl"}
$req->uri->scheme eq "https"
Truth table33%1/3
A // B
A= delete $args{"ssl"}B= $req->uri->scheme eq "https"
| |||||||||||||||||||||||||||||||||
| 46 | $self->ua->do_request( | ||||||||||||||||||||||||||||||||
| 47 | request => $req, | ||||||||||||||||||||||||||||||||
| 48 | host => $host, | ||||||||||||||||||||||||||||||||
| 49 | port => $port || ($ssl ? 443 : 80), | ||||||||||||||||||||||||||||||||
| 50 | SSL => ($ssl ? 1 : 0), | ||||||||||||||||||||||||||||||||
| 51 | %args, | ||||||||||||||||||||||||||||||||
| 52 | )->transform( | ||||||||||||||||||||||||||||||||
| 53 | done => sub { | ||||||||||||||||||||||||||||||||
| 54 | shift->decoded_content | ||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$port || ($ssl ? 443 : 80)
MC/DC0%0/2
$port || ($ssl ? 443 : 80)
$port
($ssl ? 443 : 80)
Truth table33%1/3
A || B
A= $portB= ($ssl ? 443 : 80)
| |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =head2 ua | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | Returns a L<Net::Async::HTTP> instance. | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | sub ua { | ||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
ua: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | unless($self->{ua}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | my $ua = Net::Async::HTTP->new( | ||||||||||||||||||||||||||||||||
| 69 | user_agent => $self->user_agent, | ||||||||||||||||||||||||||||||||
| 70 | max_connections_per_host => ($self->parallel // 1), | ||||||||||||||||||||||||||||||||
| 71 | pipeline => 0, | ||||||||||||||||||||||||||||||||
| 72 | fail_on_error => 1, | ||||||||||||||||||||||||||||||||
| 73 | timeout => $self->timeout, | ||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | cookie_jar => ($self->{jar} ||= HTTP::Cookies->new), | ||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->parallel // 1
$self->{"jar"} ||= "HTTP::Cookies"->new
MC/DC0%0/1
$self->parallel // 1
$self->parallel
MC/DC0%0/2
$self->{"jar"} ||= "HTTP::Cookies"->new
$self->{"jar"}
"HTTP::Cookies"->new
Truth table50%1/2
A
A= $self->parallel
Truth table33%1/3
A ||= B
A= $self->{"jar"}B= "HTTP::Cookies"->new
| |||||||||||||||||||||||||||||||||
| 75 | decode_content => 1, | ||||||||||||||||||||||||||||||||
| 76 | $self->ssl_args, | ||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||
| 78 | 1 | $self->loop->add($ua); | |||||||||||||||||||||||||||||||
| 79 | 1 | $self->{ua} = $ua; | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | 1 | $self->{ua}; | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | sub loop { shift->{loop} } | ||||||||||||||||||||||||||||||
|
Subroutine
loop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 1 | 1; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | Tom Molesworth <cpan@perlsite.co.uk> | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =head1 LICENSE | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | Copyright Tom Molesworth 2012-2015. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||