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   435 use strict;
  52         108  
  52         2161  
3 52     52   187 use warnings;
  52         78  
  52         2886  
4 52     52   37892 use HTTP::Tiny;
  52         905402  
  52         3621  
5 52     52   35916 use HTTP::Response;
  52         326135  
  52         3166  
6 52     52   5374 use Hash::MultiValue;
  52         25158  
  52         13092  
7              
8             sub new {
9 17     17 0 99 my $class = shift;
10 17         100 my $self = bless {}, $class;
11 17 50       937 $self->{http} = @_ == 1 ? $_[0] : HTTP::Tiny->new(verify_SSL => 1, @_);
12 17         3917 $self;
13             }
14              
15             sub request {
16 89     89 0 278 my($self, $req) = @_;
17              
18 89         147 my @headers;
19 89     107   629 $req->headers->scan(sub { push @headers, @_ });
  107         3329  
20              
21 89         2191 my $options = {
22             headers => Hash::MultiValue->new(@headers)->mixed,
23             };
24 89 100 66     8107 $options->{content} = $req->content if defined $req->content && length($req->content);
25              
26 89         3784 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         53826209 );
34 89         37453 $res->request($req);
35              
36 89         3866 return $res;
37             }
38              
39             1;
40              
41             __END__