File Coverage

blib/lib/Plack/LWPish.pm
Criterion Covered Total %
statement 29 29 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 8 8 100.0
pod 0 2 0.0
total 42 46 91.3


line stmt bran cond sub pod time code
1             package Plack::LWPish;
2 52     52   296 use strict;
  52         103  
  52         1398  
3 52     52   164 use warnings;
  52         96  
  52         1853  
4 52     52   29412 use HTTP::Tiny;
  52         563827  
  52         2014  
5 52     52   16071 use HTTP::Response;
  52         217847  
  52         1527  
6 52     52   4126 use Hash::MultiValue;
  52         15723  
  52         9674  
7              
8             sub new {
9 17     17 0 100 my $class = shift;
10 17         82 my $self = bless {}, $class;
11 17 50       575 $self->{http} = @_ == 1 ? $_[0] : HTTP::Tiny->new(verify_SSL => 1, @_);
12 17         3408 $self;
13             }
14              
15             sub request {
16 89     89 0 239 my($self, $req) = @_;
17              
18 89         139 my @headers;
19 89     107   528 $req->headers->scan(sub { push @headers, @_ });
  107         2722  
20              
21 89         1901 my $options = {
22             headers => Hash::MultiValue->new(@headers)->mixed,
23             };
24 89 100 66     6256 $options->{content} = $req->content if defined $req->content && length($req->content);
25              
26 89         3075 my $response = $self->{http}->request($req->method, $req->url, $options);
27              
28             my $res = HTTP::Response->new(
29             $response->{status},
30             $response->{reason},
31             [ Hash::MultiValue->from_mixed($response->{headers})->flatten ],
32             $response->{content},
33 89         35454397 );
34 89         29255 $res->request($req);
35              
36 89         2987 return $res;
37             }
38              
39             1;
40              
41             __END__