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   499 use strict;
  61         147  
  61         2750  
3 61     61   368 use warnings;
  61         133  
  61         4520  
4              
5 61     61   417 use Carp;
  61         136  
  61         5552  
6 61     61   2584 use HTTP::Request;
  61         79297  
  61         2444  
7 61     61   32783 use HTTP::Response;
  61         503080  
  61         2912  
8 61     61   35010 use HTTP::Message::PSGI;
  61         258  
  61         4730  
9 61     61   456 use Try::Tiny;
  61         157  
  61         17065  
10              
11             sub new {
12 118     118 0 363 my($class, $app) = @_;
13 118         703 bless { app => $app }, $class;
14             }
15              
16             sub request {
17 286     286 0 5444 my($self, $req) = @_;
18              
19 286 100       1158 $req->uri->scheme('http') unless defined $req->uri->scheme;
20 286 100       154821 $req->uri->host('localhost') unless defined $req->uri->host;
21 286         43441 my $env = $req->to_psgi;
22              
23             my $res = try {
24 286     286   16679 HTTP::Response->from_psgi($self->{app}->($env));
25             } catch {
26 23     23   537 HTTP::Response->from_psgi([ 500, [ 'Content-Type' => 'text/plain' ], [ $_ ] ]);
27 286         2819 };
28              
29 286         7210 $res->request($req);
30 286         8457 return $res;
31             }
32              
33             1;
34              
35             __END__