| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Async::Webservice::Common::WithUserAgent; |
|
2
|
|
|
|
|
|
|
$Net::Async::Webservice::Common::WithUserAgent::VERSION = '1.0.2'; |
|
3
|
|
|
|
|
|
|
{ |
|
4
|
|
|
|
|
|
|
$Net::Async::Webservice::Common::WithUserAgent::DIST = 'Net-Async-Webservice-Common'; |
|
5
|
|
|
|
|
|
|
} |
|
6
|
1
|
|
|
1
|
|
32410
|
use Moo::Role; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
8
|
|
|
7
|
1
|
|
|
1
|
|
1134
|
use Net::Async::Webservice::Common::Types qw(AsyncUserAgent); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
16
|
|
|
8
|
1
|
|
|
1
|
|
497
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9
|
|
|
9
|
1
|
|
|
1
|
|
95
|
use 5.010; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
174
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: user_agent attribute, sync or async |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has user_agent => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
isa => AsyncUserAgent, |
|
17
|
|
|
|
|
|
|
required => 1, |
|
18
|
|
|
|
|
|
|
coerce => AsyncUserAgent->coercion, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
around BUILDARGS => sub { |
|
22
|
|
|
|
|
|
|
my ($orig,$class,@args) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $ret = $class->$orig(@args); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if (ref $ret->{loop} && !$ret->{user_agent}) { |
|
27
|
|
|
|
|
|
|
require Net::Async::HTTP; |
|
28
|
|
|
|
|
|
|
$ret->{user_agent} = Net::Async::HTTP->new(); |
|
29
|
|
|
|
|
|
|
$ret->{loop}->add($ret->{user_agent}); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return $ret; |
|
33
|
|
|
|
|
|
|
}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding UTF-8 |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Net::Async::Webservice::Common::WithUserAgent - user_agent attribute, sync or async |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 VERSION |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
version 1.0.2 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package My::WS::Client { |
|
54
|
|
|
|
|
|
|
use Moo; |
|
55
|
|
|
|
|
|
|
with 'Net::Async::Webservice::Common::WithUserAgent'; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
use IO::Async::Loop; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $c_with_default_async_ua = My::WS::Client->new({ |
|
63
|
|
|
|
|
|
|
loop => $loop, |
|
64
|
|
|
|
|
|
|
}); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $async_ua = Net::Async::HTTP->new(); |
|
68
|
|
|
|
|
|
|
$loop->add($async_ua); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $c_with_custom_async_ua = My::WS::Client->new({ |
|
71
|
|
|
|
|
|
|
user_agent => $async_ua, |
|
72
|
|
|
|
|
|
|
}); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $sync_ua = LWP::UserAgent->new(); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $c_with_custom_async_ua = My::WS::Client->new({ |
|
78
|
|
|
|
|
|
|
user_agent => $sync_ua, |
|
79
|
|
|
|
|
|
|
}); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This role provides a C<user_agent> attribute, guaranteed to work |
|
84
|
|
|
|
|
|
|
mostly like a L<Net::Async::HTTP>. If a L<LWP::UserAgent>-like object |
|
85
|
|
|
|
|
|
|
is passed in, L<Net::Async::Webservice::Common::SyncAgentWrapper> is |
|
86
|
|
|
|
|
|
|
used to wrap it. You can also pass the C<loop> constructor parameter |
|
87
|
|
|
|
|
|
|
to get a default L<Net::Async::HTTP> instance. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 C<user_agent> |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
A user agent object, looking either like L<Net::Async::HTTP> (has |
|
94
|
|
|
|
|
|
|
C<do_request>, C<GET>, and C<POST>) or like L<LWP::UserAgent> (has |
|
95
|
|
|
|
|
|
|
C<request>, C<get>, and C<post>). |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHODS |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 C<BUILDARGS> |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 C<new> |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
As you can see in the L</SYNOPSIS>, you can construct objects of classes consuming this role is a few different ways: |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$class->new({ |
|
106
|
|
|
|
|
|
|
user_agent => $async_ua, |
|
107
|
|
|
|
|
|
|
}); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
will just set the L</user_agent>. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$class->new({ loop => $loop }); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
will construct a L<Net::Async::HTTP>, set it as L</user_agent>, and |
|
114
|
|
|
|
|
|
|
register it to the loop. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$class->new({ |
|
117
|
|
|
|
|
|
|
user_agent => $sync_ua, |
|
118
|
|
|
|
|
|
|
}); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
will set the L</user_agent> to an instance of |
|
121
|
|
|
|
|
|
|
L<Net::Async::Webservice::Common::SyncAgentWrapper> wrapping the |
|
122
|
|
|
|
|
|
|
C<$sync_ua>. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Net-a-porter.com. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
133
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |