line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Async::UserAgent::NaHTTP; |
2
|
|
|
|
|
|
|
$WebService::Async::UserAgent::NaHTTP::VERSION = '0.004'; |
3
|
1
|
|
|
1
|
|
125491
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
380
|
use parent qw(WebService::Async::UserAgent); |
|
1
|
|
|
|
|
215
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
WebService::Async::UserAgent::NaHTTP - make requests using L |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 0.004 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Provides a L method which will use L to make |
19
|
|
|
|
|
|
|
requests and return a L containing the result. Used internally by |
20
|
|
|
|
|
|
|
L. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
44
|
use Future; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
25
|
1
|
|
|
1
|
|
4
|
use Net::Async::HTTP; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
26
|
1
|
|
|
1
|
|
431
|
use HTTP::Cookies; |
|
1
|
|
|
|
|
8296
|
|
|
1
|
|
|
|
|
225
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 request |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Issues the request. Expects a single L object, |
31
|
|
|
|
|
|
|
and returns a L 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
|
|
|
1
|
1
|
2
|
my ($self, $req, %args) = @_; |
38
|
1
|
|
|
|
|
3
|
my $host = delete $args{host}; |
39
|
1
|
|
|
|
|
2
|
my $port = delete $args{port}; |
40
|
1
|
50
|
33
|
|
|
7
|
unless(defined($host) && defined($port)) { |
41
|
1
|
|
|
|
|
4
|
my ($h, $p) = split /:/, '' . $req->uri->host_port; |
42
|
1
|
|
33
|
|
|
28
|
$host //= $h; |
43
|
1
|
|
33
|
|
|
4
|
$port //= $p; |
44
|
|
|
|
|
|
|
} |
45
|
1
|
|
33
|
|
|
4
|
my $ssl = delete($args{ssl}) // ($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
|
|
|
1
|
|
23041
|
}, |
56
|
1
|
50
|
33
|
|
|
42
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 ua |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns a L instance. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub ua { |
66
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
67
|
1
|
50
|
|
|
|
6
|
unless($self->{ua}) { |
68
|
1
|
|
50
|
|
|
8
|
my $ua = Net::Async::HTTP->new( |
|
|
|
33
|
|
|
|
|
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
|
|
|
|
|
|
|
cookie_jar => ($self->{jar} ||= HTTP::Cookies->new), |
75
|
|
|
|
|
|
|
decode_content => 1, |
76
|
|
|
|
|
|
|
$self->ssl_args, |
77
|
|
|
|
|
|
|
); |
78
|
1
|
|
|
|
|
82
|
$self->loop->add($ua); |
79
|
1
|
|
|
|
|
44
|
$self->{ua} = $ua; |
80
|
|
|
|
|
|
|
} |
81
|
1
|
|
|
|
|
12
|
$self->{ua}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
1
|
0
|
4
|
sub loop { shift->{loop} } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Tom Molesworth |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 LICENSE |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Copyright Tom Molesworth 2012-2015. Licensed under the same terms as Perl itself. |