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   3242098 use strict;
  74         118  
  74         2153  
3 74     74   457 use warnings;
  74         113  
  74         2833  
4 74     74   375 use Carp;
  74         132  
  74         4579  
5 74     74   15354 use parent qw(Exporter);
  74         10705  
  74         358  
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 201773 my($class, $app, @args) = @_;
13              
14 129         279 my $subclass = "Plack::Test::$Impl";
15 129         6891 eval "require $subclass";
16 129 50       627 die $@ if $@;
17              
18 74     74   9536 no strict 'refs';
  74         118  
  74         18419  
19 129 50       203 if (defined &{"Plack::Test::$Impl\::test_psgi"}) {
  129         839  
20 0         0 return \&{"Plack::Test::$Impl\::test_psgi"};
  0         0  
21             }
22              
23 129         617 $subclass->new($app, @args);
24             }
25              
26             sub test_psgi {
27 128 100 66 128 1 4072806 if (ref $_[0] && @_ == 2) {
28 89         325 @_ = (app => $_[0], client => $_[1]);
29             }
30 128         438 my %args = @_;
31              
32 128         270 my $app = delete $args{app}; # Backward compat: some implementations don't need app
33 128 50       404 my $client = delete $args{client} or Carp::croak "client test code needed";
34              
35 128         812 my $tester = Plack::Test->create($app, %args);
36 128 50       661 return $tester->(@_) if ref $tester eq 'CODE'; # compatibility
37              
38 128     300   1442 $client->(sub { $tester->request(@_) });
  300         747103  
39             }
40              
41             1;
42              
43             __END__