| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Async::Webservice::Common::SyncAgentWrapper; |
|
2
|
|
|
|
|
|
|
$Net::Async::Webservice::Common::SyncAgentWrapper::VERSION = '1.0.2'; |
|
3
|
|
|
|
|
|
|
{ |
|
4
|
|
|
|
|
|
|
$Net::Async::Webservice::Common::SyncAgentWrapper::DIST = 'Net-Async-Webservice-Common'; |
|
5
|
|
|
|
|
|
|
} |
|
6
|
2
|
|
|
2
|
|
210258
|
use Moo; |
|
|
2
|
|
|
|
|
22461
|
|
|
|
2
|
|
|
|
|
14
|
|
|
7
|
2
|
|
|
2
|
|
5870
|
use Net::Async::Webservice::Common::Types 'SyncUserAgent'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
32
|
|
|
8
|
2
|
|
|
2
|
|
2056
|
use HTTP::Request; |
|
|
2
|
|
|
|
|
42114
|
|
|
|
2
|
|
|
|
|
79
|
|
|
9
|
2
|
|
|
2
|
|
3206
|
use HTTP::Request::Common qw(); |
|
|
2
|
|
|
|
|
4759
|
|
|
|
2
|
|
|
|
|
45
|
|
|
10
|
2
|
|
|
2
|
|
1987
|
use Future; |
|
|
2
|
|
|
|
|
17163
|
|
|
|
2
|
|
|
|
|
76
|
|
|
11
|
2
|
|
|
2
|
|
21
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
162
|
|
|
12
|
2
|
|
|
2
|
|
10
|
use Scalar::Util 'blessed'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
77
|
|
|
13
|
2
|
|
|
2
|
|
11
|
use namespace::autoclean; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: minimal wrapper to adapt a sync UA |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has ua => ( |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
isa => SyncUserAgent, |
|
21
|
|
|
|
|
|
|
required => 1, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub do_request { |
|
26
|
5
|
|
|
5
|
1
|
43726
|
my ($self,%args) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
5
|
100
|
|
|
|
21
|
if( my $uri = delete $args{uri} ) { |
|
29
|
1
|
|
|
|
|
8
|
%args = $self->_make_request( $uri, %args ); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
13
|
my $request = $args{request}; |
|
33
|
5
|
|
|
|
|
11
|
my $fail = $args{fail_on_error}; |
|
34
|
5
|
100
|
|
|
|
39
|
my %ssl = map { m/^SSL_/ ? ( $_ => $args{$_} ) : () } keys %args; |
|
|
13
|
|
|
|
|
41
|
|
|
35
|
5
|
100
|
66
|
|
|
67
|
if ($self->ua->can('ssl_opts') && %ssl) { |
|
36
|
1
|
|
|
|
|
8
|
$self->ua->ssl_opts(%ssl); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
29
|
my $response = $self->ua->request($request); |
|
40
|
5
|
100
|
66
|
|
|
86
|
if ($fail && ! $response->is_success) { |
|
41
|
1
|
|
|
|
|
17
|
return Future->new->fail($response->status_line,'http',$response,$request); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
4
|
|
|
|
|
26
|
return Future->wrap($response); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _make_request |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
49
|
1
|
|
|
|
|
4
|
my ( $uri, %args ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
1
|
50
|
0
|
|
|
7
|
if( !ref $uri ) { |
|
|
|
0
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
9
|
$uri = URI->new( $uri ); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
elsif( blessed $uri and !$uri->isa( "URI" ) ) { |
|
55
|
0
|
|
|
|
|
0
|
croak "Expected 'uri' as a URI reference"; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
1
|
|
50
|
|
|
10604
|
my $method = delete $args{method} || "GET"; |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
11
|
$args{host} = $uri->host; |
|
61
|
1
|
|
|
|
|
211
|
$args{port} = $uri->port; |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
27
|
my $request; |
|
64
|
|
|
|
|
|
|
|
|
65
|
1
|
50
|
|
|
|
5
|
if( $method eq "POST" ) { |
|
66
|
1
|
50
|
|
|
|
5
|
defined $args{content} or croak "Expected 'content' with POST method"; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Lack of content_type didn't used to be a failure condition: |
|
69
|
1
|
50
|
33
|
|
|
10
|
ref $args{content} or defined $args{content_type} or |
|
70
|
|
|
|
|
|
|
carp "No 'content_type' was given with 'content'"; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# This will automatically encode a form for us |
|
73
|
1
|
|
|
|
|
8
|
$request = HTTP::Request::Common::POST( $uri, Content => $args{content}, Content_Type => $args{content_type} ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
else { |
|
76
|
0
|
|
|
|
|
0
|
$request = HTTP::Request->new( $method, $uri ); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
469
|
$request->protocol( "HTTP/1.1" ); |
|
80
|
1
|
|
|
|
|
18
|
$request->header( Host => $uri->host ); |
|
81
|
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
70
|
my ( $user, $pass ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
1
|
50
|
33
|
|
|
9
|
if( defined $uri->userinfo ) { |
|
|
|
50
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
( $user, $pass ) = split( m/:/, $uri->userinfo, 2 ); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
elsif( defined $args{user} and defined $args{pass} ) { |
|
88
|
1
|
|
|
|
|
29
|
$user = $args{user}; |
|
89
|
1
|
|
|
|
|
2
|
$pass = $args{pass}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
1
|
50
|
33
|
|
|
8
|
if( defined $user and defined $pass ) { |
|
93
|
1
|
|
|
|
|
10
|
$request->authorization_basic( $user, $pass ); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
4268
|
$args{request} = $request; |
|
97
|
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
42
|
return %args; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub GET { |
|
103
|
0
|
|
|
0
|
1
|
|
my ($self, $uri, @args) = @_; |
|
104
|
0
|
|
|
|
|
|
return $self->do_request( method => "GET", uri => $uri, @args ); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub HEAD { |
|
108
|
0
|
|
|
0
|
1
|
|
my ($self, $uri, @args) = @_; |
|
109
|
0
|
|
|
|
|
|
return $self->do_request( method => "HEAD", uri => $uri, @args ); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub POST { |
|
113
|
0
|
|
|
0
|
1
|
|
my ($self, $uri, $content, @args) = @_; |
|
114
|
0
|
|
|
|
|
|
return $self->do_request( method => "POST", uri => $uri, content => $content, @args ); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=pod |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=encoding UTF-8 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Net::Async::Webservice::Common::SyncAgentWrapper - minimal wrapper to adapt a sync UA |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 VERSION |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
version 1.0.2 |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This class wraps an instance of L<LWP::UserAgent> (or something that |
|
136
|
|
|
|
|
|
|
looks like it) to allow it to be used as if it were a |
|
137
|
|
|
|
|
|
|
L<Net::Async::HTTP>. It is I<very> limited at the moment, please read |
|
138
|
|
|
|
|
|
|
all of this document and, if you need more power, submit a bug |
|
139
|
|
|
|
|
|
|
request. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
An instance of this class will be automatically created if you pass a |
|
142
|
|
|
|
|
|
|
L<LWP::UserAgent> (or something that looks like it) to the constructor |
|
143
|
|
|
|
|
|
|
for a class doing |
|
144
|
|
|
|
|
|
|
L<Net::Async::Webservice::Common::WithUserAgent>. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 C<ua> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
The actual user agent instance. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 METHODS |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 C<do_request> |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Delegates to C<< $self->ua->request >>, and returns an immediate |
|
157
|
|
|
|
|
|
|
L<Future>. It supports just a few of the options you can pass to the |
|
158
|
|
|
|
|
|
|
actual method in L<Net::Async::HTTP>. These are supported: |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=over 4 |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
C<< request => >> L<HTTP::Request> |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
C<< host => >> string |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
C<< port => >> int or string |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
C<< uri => >> L<URI> or string |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
C<< method => >> string |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
C<< content => >> string or arrayref |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
C<< content_type => >> string |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
C<< user => >> string |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
C<< pass => >> string |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
C<< fail_on_error => >> boolean |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
In additon, options with keys of the form C<< SSL_* >> will be set via |
|
205
|
|
|
|
|
|
|
the C<ssl_opts> method, if the underlying user agent supports it. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 C<GET> |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
$ua->GET( $uri, %args ) ==> $response |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 C<HEAD> |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
$ua->HEAD( $uri, %args ) ==> $response |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 C<POST> |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$ua->POST( $uri, $content, %args ) ==> $response |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Convenient wrappers for using the C<GET>, C<HEAD> or C<POST> methods with a |
|
220
|
|
|
|
|
|
|
C<URI> object and few if any other arguments, returning a C<Future>. |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Please check the documentation of L</do_request> for the values you |
|
223
|
|
|
|
|
|
|
can usefully pass in C<%args>. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 AUTHOR |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Net-a-porter.com. |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
234
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |