File Coverage

blib/lib/Plack/Test/MockHTTP.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 4 100.0
condition n/a
subroutine 11 11 100.0
pod 0 2 0.0
total 47 49 95.9


line stmt bran cond sub pod time code
1             package Plack::Test::MockHTTP;
2 61     61   405 use strict;
  61         95  
  61         2232  
3 61     61   263 use warnings;
  61         100  
  61         3472  
4              
5 61     61   273 use Carp;
  61         94  
  61         4220  
6 61     61   1859 use HTTP::Request;
  61         64961  
  61         1802  
7 61     61   25991 use HTTP::Response;
  61         325891  
  61         1996  
8 61     61   23966 use HTTP::Message::PSGI;
  61         151  
  61         3523  
9 61     61   21766 use Try::Tiny;
  61         87482  
  61         12725  
10              
11             sub new {
12 118     118 0 280 my($class, $app) = @_;
13 118         523 bless { app => $app }, $class;
14             }
15              
16             sub request {
17 286     286 0 5960 my($self, $req) = @_;
18              
19 286 100       743 $req->uri->scheme('http') unless defined $req->uri->scheme;
20 286 100       100747 $req->uri->host('localhost') unless defined $req->uri->host;
21 286         27781 my $env = $req->to_psgi;
22              
23             my $res = try {
24 286     286   11912 HTTP::Response->from_psgi($self->{app}->($env));
25             } catch {
26 23     23   304 HTTP::Response->from_psgi([ 500, [ 'Content-Type' => 'text/plain' ], [ $_ ] ]);
27 286         1809 };
28              
29 286         4739 $res->request($req);
30 286         5191 return $res;
31             }
32              
33             1;
34              
35             __END__