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   4578154 use strict;
  74         159  
  74         2848  
3 74     74   637 use warnings;
  74         161  
  74         4173  
4 74     74   622 use Carp;
  74         282  
  74         6097  
5 74     74   20892 use parent qw(Exporter);
  74         14537  
  74         509  
6             our @EXPORT = qw(test_psgi);
7              
8             our $Impl;
9             $Impl ||= $ENV{PLACK_TEST_IMPL} || "MockHTTP";
10              
11             sub create {
12 129     129 1 314551 my($class, $app, @args) = @_;
13              
14 129         328 my $subclass = "Plack::Test::$Impl";
15 129         9769 eval "require $subclass";
16 129 50       855 die $@ if $@;
17              
18 74     74   14055 no strict 'refs';
  74         161  
  74         27684  
19 129 50       319 if (defined &{"Plack::Test::$Impl\::test_psgi"}) {
  129         1276  
20 0         0 return \&{"Plack::Test::$Impl\::test_psgi"};
  0         0  
21             }
22              
23 129         837 $subclass->new($app, @args);
24             }
25              
26             sub test_psgi {
27 128 100 66 128 1 5975677 if (ref $_[0] && @_ == 2) {
28 89         432 @_ = (app => $_[0], client => $_[1]);
29             }
30 128         604 my %args = @_;
31              
32 128         430 my $app = delete $args{app}; # Backward compat: some implementations don't need app
33 128 50       548 my $client = delete $args{client} or Carp::croak "client test code needed";
34              
35 128         1255 my $tester = Plack::Test->create($app, %args);
36 128 50       687 return $tester->(@_) if ref $tester eq 'CODE'; # compatibility
37              
38 128     300   1751 $client->(sub { $tester->request(@_) });
  300         1086900  
39             }
40              
41             1;
42              
43             __END__