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   481 use strict;
  61         157  
  61         2678  
3 61     61   10441 use warnings;
  61         180  
  61         4802  
4              
5 61     61   414 use Carp;
  61         127  
  61         5096  
6 61     61   2290 use HTTP::Request;
  61         84440  
  61         2406  
7 61     61   31344 use HTTP::Response;
  61         473519  
  61         2652  
8 61     61   33586 use HTTP::Message::PSGI;
  61         207  
  61         4545  
9 61     61   28693 use Try::Tiny;
  61         121471  
  61         17426  
10              
11             sub new {
12 118     118 0 369 my($class, $app) = @_;
13 118         668 bless { app => $app }, $class;
14             }
15              
16             sub request {
17 286     286 0 6423 my($self, $req) = @_;
18              
19 286 100       946 $req->uri->scheme('http') unless defined $req->uri->scheme;
20 286 100       139349 $req->uri->host('localhost') unless defined $req->uri->host;
21 286         38272 my $env = $req->to_psgi;
22              
23             my $res = try {
24 286     286   15675 HTTP::Response->from_psgi($self->{app}->($env));
25             } catch {
26 23     23   527 HTTP::Response->from_psgi([ 500, [ 'Content-Type' => 'text/plain' ], [ $_ ] ]);
27 286         2581 };
28              
29 286         6320 $res->request($req);
30 286         7178 return $res;
31             }
32              
33             1;
34              
35             __END__