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   2159705 use strict;
  74         533  
  74         1869  
3 74     74   309 use warnings;
  74         127  
  74         1662  
4 74     74   318 use Carp;
  74         127  
  74         4480  
5 74     74   19013 use parent qw(Exporter);
  74         14272  
  74         400  
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 425 my($class, $app, @args) = @_;
13              
14 128         364 my $subclass = "Plack::Test::$Impl";
15 128         6042 eval "require $subclass";
16 128 50       667 die $@ if $@;
17              
18 74     74   8656 no strict 'refs';
  74         203  
  74         15813  
19 128 50       242 if (defined &{"Plack::Test::$Impl\::test_psgi"}) {
  128         907  
20 0         0 return \&{"Plack::Test::$Impl\::test_psgi"};
  0         0  
21             }
22              
23 128         675 $subclass->new($app, @args);
24             }
25              
26             sub test_psgi {
27 127 100 66 127 1 45715 if (ref $_[0] && @_ == 2) {
28 89         296 @_ = (app => $_[0], client => $_[1]);
29             }
30 127         408 my %args = @_;
31              
32 127         303 my $app = delete $args{app}; # Backward compat: some implementations don't need app
33 127 50       411 my $client = delete $args{client} or Carp::croak "client test code needed";
34              
35 127         648 my $tester = Plack::Test->create($app, %args);
36 127 50       658 return $tester->(@_) if ref $tester eq 'CODE'; # compatibility
37              
38 127     299   1025 $client->(sub { $tester->request(@_) });
  299         546138  
39             }
40              
41             1;
42              
43             __END__