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         2216  
3 61     61   258 use warnings;
  61         119  
  61         3452  
4              
5 61     61   273 use Carp;
  61         88  
  61         4305  
6 61     61   1761 use HTTP::Request;
  61         60244  
  61         1769  
7 61     61   24573 use HTTP::Response;
  61         323286  
  61         1915  
8 61     61   23892 use HTTP::Message::PSGI;
  61         158  
  61         3572  
9 61     61   21410 use Try::Tiny;
  61         88517  
  61         12851  
10              
11             sub new {
12 118     118 0 280 my($class, $app) = @_;
13 118         511 bless { app => $app }, $class;
14             }
15              
16             sub request {
17 287     287 0 7053 my($self, $req) = @_;
18              
19 287 100       844 $req->uri->scheme('http') unless defined $req->uri->scheme;
20 287 100       104738 $req->uri->host('localhost') unless defined $req->uri->host;
21 287         28895 my $env = $req->to_psgi;
22              
23             my $res = try {
24 287     287   12076 HTTP::Response->from_psgi($self->{app}->($env));
25             } catch {
26 23     23   312 HTTP::Response->from_psgi([ 500, [ 'Content-Type' => 'text/plain' ], [ $_ ] ]);
27 287         2128 };
28              
29 287         5199 $res->request($req);
30 287         5379 return $res;
31             }
32              
33             1;
34              
35             __END__