File Coverage

blib/lib/WWW/VastAI/LWPIO.pm
Criterion Covered Total %
statement 20 21 95.2
branch 1 2 50.0
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 27 30 90.0


line stmt bran cond sub pod time code
1             package WWW::VastAI::LWPIO;
2             our $VERSION = '0.001';
3             # ABSTRACT: Default LWP::UserAgent-backed IO backend for WWW::VastAI
4              
5 11     11   549 use Moo;
  11         25  
  11         67  
6 11     11   4267 use HTTP::Request;
  11         21122  
  11         448  
7 11     11   772 use LWP::UserAgent;
  11         28830  
  11         327  
8 11     11   1812 use WWW::VastAI::HTTPResponse;
  11         31  
  11         2757  
9              
10             with 'WWW::VastAI::Role::IO';
11              
12             has user_agent => (
13             is => 'lazy',
14             builder => sub {
15 0     0   0 LWP::UserAgent->new(
16             agent => 'WWW-VastAI',
17             timeout => 30,
18             );
19             },
20             );
21              
22             sub call {
23 1     1 1 5677 my ($self, $req) = @_;
24              
25 1         15 my $http = HTTP::Request->new($req->method => $req->url);
26 1         8812 for my $name (keys %{ $req->headers }) {
  1         7  
27 2         200 $http->header($name => $req->headers->{$name});
28             }
29 1 50       51 $http->content($req->content) if $req->has_content;
30              
31 1         57 my $response = $self->user_agent->request($http);
32              
33 1         28 return WWW::VastAI::HTTPResponse->new(
34             status => $response->code,
35             content => $response->decoded_content,
36             );
37             }
38              
39             1;
40              
41             __END__