| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Async::Graphite::HTTPClient; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.1_1'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::Async::Graphite::HTTPClient - Handle HTTP for Net::Async::Graphite |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Net::Async::Graphite::HTTPClient'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Don't use this module directly, use L and create |
|
16
|
|
|
|
|
|
|
objects using its C method in the normal way. Those objects will |
|
17
|
|
|
|
|
|
|
include the functionality documented here. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This role brings the capacity to communicate with an HTTP server. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
It's mixed in by L and uses a |
|
22
|
|
|
|
|
|
|
L object to do its work. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 BUGS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
C<_http> is added to L's loop but there's no mechanism to |
|
27
|
|
|
|
|
|
|
remove it. For now C<_http> exists until the application exits but if |
|
28
|
|
|
|
|
|
|
that ever changes this will be the source of memory leaks at best. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
3
|
|
|
3
|
|
1505
|
use v5.14; |
|
|
3
|
|
|
|
|
9
|
|
|
33
|
3
|
|
|
3
|
|
16
|
use strictures 2; |
|
|
3
|
|
|
|
|
21
|
|
|
|
3
|
|
|
|
|
103
|
|
|
34
|
3
|
|
|
3
|
|
594
|
use Moo::Role; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
16
|
|
|
35
|
3
|
|
|
3
|
|
1151
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
157
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
3
|
|
|
3
|
|
1380
|
use Net::Async::HTTP; |
|
|
3
|
|
|
|
|
242729
|
|
|
|
3
|
|
|
|
|
125
|
|
|
38
|
3
|
|
|
3
|
|
26
|
use Scalar::Util qw(blessed); |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
147
|
|
|
39
|
3
|
|
|
3
|
|
18
|
use namespace::clean; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
26
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 ROLE |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This role requires the L functionality defined in |
|
44
|
|
|
|
|
|
|
L (essentially just a C<_loop> attribute |
|
45
|
|
|
|
|
|
|
to hold the L object). |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
with 'Net::Async::Graphite::Async'; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item max_connections (read-only) |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
The maximum number of simultaneous HTTP connections to allow. See |
|
58
|
|
|
|
|
|
|
C in L. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Default: 0; no limit. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has max_connections => is => ro => default => 0; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item username (read-only, predicable) |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item password (read-only, predicable) |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The username and password to authenticate with. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
In addition to the predicates C and C |
|
73
|
|
|
|
|
|
|
there is C which returns true if there is a username I |
|
74
|
|
|
|
|
|
|
a password. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has [qw(username password)] => is => ro => predicate => 1; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
0
|
0
|
|
sub has_auth { $_[0]->has_username and $_[0]->has_password } |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item _http (read-only) |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
The L object which performs the HTTP queries. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
has _http => is => lazy => init_arg => undef, builder => sub { |
|
89
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
90
|
0
|
|
|
|
|
|
my $http = Net::Async::HTTP->new( |
|
91
|
|
|
|
|
|
|
user_agent => blessed($self) .'/0.0', |
|
92
|
|
|
|
|
|
|
max_connections_per_host => $self->max_connections, |
|
93
|
|
|
|
|
|
|
); |
|
94
|
0
|
|
|
|
|
|
$self->_loop->add($http); |
|
95
|
0
|
|
|
|
|
|
$http; |
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=back |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 PRIVATE METHODS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item _download ($uri) |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Return (a L which completes with) an L object |
|
107
|
|
|
|
|
|
|
when the HTTP request has finished. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _download { |
|
112
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
113
|
0
|
|
|
|
|
|
my ($uri) = @_; |
|
114
|
|
|
|
|
|
|
#$self->_debugf("Downloading from uri <%s>.", $uri); |
|
115
|
|
|
|
|
|
|
$self->_http->do_request( |
|
116
|
|
|
|
|
|
|
uri => "$uri", |
|
117
|
|
|
|
|
|
|
# timeout=> ?, |
|
118
|
|
|
|
0
|
|
|
on_error => sub { |
|
119
|
|
|
|
|
|
|
#$self->_errorf('Error conducting HTTP transaction to %s?%s: %s', |
|
120
|
|
|
|
|
|
|
# $self->endpoint, $uri, $_[0]); |
|
121
|
|
|
|
|
|
|
# Future has already been fail()ed elsewhere. |
|
122
|
|
|
|
|
|
|
}, |
|
123
|
0
|
0
|
|
|
|
|
($self->has_auth |
|
124
|
|
|
|
|
|
|
? (user => $self->username, pass => $self->password) |
|
125
|
|
|
|
|
|
|
: ())); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Matthew King |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |