Graphite/HTTPClient.pm

filter: Statementstmt 68.4% 26 / 38 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 1 totaltotal 60.0% 33 / 55 CC 3 SCAR 9.4
CC
3
Cov
62%
has_auth
6.0
_download
6.0
__ANON__
2.0
CRAP 2.6
« Graphite/API.pm ↑ Summary Graphite/Async.pm »
1 package Net::Async::Graphite::HTTPClient;
2  
3 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<Net::Async::Graphite> and create
16 objects using its C<new> 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<Net::Async::Graphite::API> and uses a
22 L<Net::Async::HTTP> object to do its work.
23  
24 =head1 BUGS
25  
26 C<_http> is added to L<IO::Async>'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 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 3 ▶use Net::Async::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 =head1 ROLE
42  
43 This role requires the L<IO::Async> functionality defined in
44 L<Net::Async::Graphite::Async> (essentially just a C<_loop> attribute
45 to hold the L<IO::Async::Loop> object).
46  
47 =cut
48  
49 3 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<max_connections_per_host> in L<Net::Async::HTTP>.
59  
60 Default: 0; no limit.
61  
62 =cut
63  
64 3 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<has_username> and C<has_password>
73 there is C<has_auth> which returns true if there is a username I<and>
74 a password.
75  
76 =cut
77  
78 3 has [qw(username password)] => is => ro => predicate => 1;
79  
80 0 ▶sub has_auth { $_[0]->has_username and $_[0]->has_password }
Subroutine has_auth: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->has_username and $_[0]->has_password 0 0 0
81  
82 =item _http (read-only)
83  
84 The L<Net::Async::HTTP> object which performs the HTTP queries.
85  
86 =cut
87  
88 0 ▶has _http => is => lazy => init_arg => undef, builder => sub {
Subroutine _build__http: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 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 3 };
97  
98 =back
99  
100 =head1 PRIVATE METHODS
101  
102 =over
103  
104 =item _download ($uri)
105  
106 Return (a L<Future> which completes with) an L<HTTP::Response> object
107 when the HTTP request has finished.
108  
109 =cut
110  
111 0 ▶sub _download {
Subroutine _download: not called CC=2 SCAR=17.9
112 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 {
Subroutine __ANON__: not called CC=1 SCAR=0.0
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 ▶ ($self->has_auth
Branch: 1 branch
BranchTrueFalseTotal
$self->has_auth ? : 0 0 0
124 ? (user => $self->username, pass => $self->password)
125 : ()));
126 }
127  
128 3 1;
129  
130 =back
131  
132 =head1 SEE ALSO
133  
134 L<Net::Async::Graphite>
135  
136 L<Net::Async::Graphite::Async>
137  
138 L<Net::Async::HTTP>
139  
140 L<Future>
141  
142 L<Moo>
143  
144 =head1 AUTHOR
145  
146 Matthew King <matthew.king@cloudbeds.com>
147  
148 =cut
« Graphite/API.pm ↑ Summary Graphite/Async.pm »