File Coverage

blib/lib/WWW/Hetzner/LWPIO.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 2 0.0
condition 0 2 0.0
subroutine 5 6 83.3
pod 1 1 100.0
total 20 33 60.6


line stmt bran cond sub pod time code
1             package WWW::Hetzner::LWPIO;
2              
3             # ABSTRACT: Synchronous HTTP backend using LWP::UserAgent
4              
5 25     25   765 use Moo;
  25         58  
  25         163  
6 25     25   29489 use LWP::UserAgent;
  25         1551101  
  25         1176  
7 25     25   243 use HTTP::Request;
  25         95  
  25         843  
8 25     25   136 use WWW::Hetzner::HTTPResponse;
  25         56  
  25         6763  
9              
10             with 'WWW::Hetzner::Role::IO';
11              
12             our $VERSION = '0.100';
13              
14              
15             has timeout => (is => 'ro', default => 30);
16              
17              
18             has ua => (
19             is => 'lazy',
20             builder => sub {
21 1     1   26162 my $self = shift;
22 1         18 LWP::UserAgent->new(
23             agent => 'WWW-Hetzner/' . $VERSION,
24             timeout => $self->timeout,
25             );
26             },
27             );
28              
29              
30             sub call {
31 0     0 1   my ($self, $req) = @_;
32              
33 0           my $http_req = HTTP::Request->new($req->method => $req->url);
34              
35 0           my $headers = $req->headers;
36 0           for my $header (keys %$headers) {
37 0           $http_req->header($header => $headers->{$header});
38             }
39              
40 0 0         $http_req->content($req->content) if $req->has_content;
41              
42 0           my $response = $self->ua->request($http_req);
43              
44 0   0       return WWW::Hetzner::HTTPResponse->new(
45             status => $response->code,
46             content => $response->decoded_content // '',
47             );
48             }
49              
50              
51              
52             1;
53              
54             __END__