File Coverage

blib/lib/Plack/Test.pm
Criterion Covered Total %
statement 31 33 93.9
branch 6 10 60.0
condition 2 3 66.6
subroutine 8 8 100.0
pod 2 2 100.0
total 49 56 87.5


line stmt bran cond sub pod time code
1             package Plack::Test;
2 74     74   2837455 use strict;
  74         621  
  74         2222  
3 74     74   421 use warnings;
  74         158  
  74         1994  
4 74     74   408 use Carp;
  74         130  
  74         5586  
5 74     74   27201 use parent qw(Exporter);
  74         16622  
  74         435  
6             our @EXPORT = qw(test_psgi);
7              
8             our $Impl;
9             $Impl ||= $ENV{PLACK_TEST_IMPL} || "MockHTTP";
10              
11             sub create {
12 128     128 1 485 my($class, $app, @args) = @_;
13              
14 128         391 my $subclass = "Plack::Test::$Impl";
15 128         7212 eval "require $subclass";
16 128 50       807 die $@ if $@;
17              
18 74     74   10577 no strict 'refs';
  74         245  
  74         19596  
19 128 50       304 if (defined &{"Plack::Test::$Impl\::test_psgi"}) {
  128         1072  
20 0         0 return \&{"Plack::Test::$Impl\::test_psgi"};
  0         0  
21             }
22              
23 128         860 $subclass->new($app, @args);
24             }
25              
26             sub test_psgi {
27 127 100 66 127 1 50766 if (ref $_[0] && @_ == 2) {
28 89         357 @_ = (app => $_[0], client => $_[1]);
29             }
30 127         519 my %args = @_;
31              
32 127         357 my $app = delete $args{app}; # Backward compat: some implementations don't need app
33 127 50       450 my $client = delete $args{client} or Carp::croak "client test code needed";
34              
35 127         793 my $tester = Plack::Test->create($app, %args);
36 127 50       886 return $tester->(@_) if ref $tester eq 'CODE'; # compatibility
37              
38 127     299   1429 $client->(sub { $tester->request(@_) });
  299         677640  
39             }
40              
41             1;
42              
43             __END__