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 50     50   338 use strict;
  50         97  
  50         1567  
3 50     50   204 use warnings;
  50         98  
  50         1592  
4 50     50   30147 use HTTP::Tiny;
  50         554426  
  50         1957  
5 50     50   24543 use HTTP::Response;
  50         255568  
  50         2072  
6 50     50   3902 use Hash::MultiValue;
  50         16230  
  50         10933  
7              
8             sub new {
9 17     17 0 88 my $class = shift;
10 17         101 my $self = bless {}, $class;
11 17 50       548 $self->{http} = @_ == 1 ? $_[0] : HTTP::Tiny->new(verify_SSL => 1, @_);
12 17         2687 $self;
13             }
14              
15             sub request {
16 89     89 0 311 my($self, $req) = @_;
17              
18 89         158 my @headers;
19 89     107   419 $req->headers->scan(sub { push @headers, @_ });
  107         2854  
20              
21 89         1589 my $options = {
22             headers => Hash::MultiValue->new(@headers)->mixed,
23             };
24 89 100 66     6661 $options->{content} = $req->content if defined $req->content && length($req->content);
25              
26 89         3325 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         34008323 );
34 89         26700 $res->request($req);
35              
36 89         2643 return $res;
37             }
38              
39             1;
40              
41             __END__