File Coverage

blib/lib/Plack/Test/ExternalServer.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 6 50.0
condition 3 6 50.0
subroutine 7 7 100.0
pod 0 1 0.0
total 43 50 86.0


line stmt bran cond sub pod time code
1 1     1   76933 use strict;
  1         7  
  1         107  
2 1     1   15 use warnings;
  1         2  
  1         115  
3              
4             package Plack::Test::ExternalServer;
5             our $VERSION = '0.01';
6             # ABSTRACT: Run HTTP tests on external live servers
7              
8 1     1   66 use URI;
  1         3  
  1         101  
9 1     1   7 use Carp;
  1         7  
  1         220  
10 1     1   1844 use LWP::UserAgent;
  1         47797  
  1         507  
11              
12              
13             sub test_psgi {
14 2     2 0 120856 my %args = @_;
15              
16 2 50       18 my $client = delete $args{client} or croak 'client test code needed';
17 2   33     38 my $ua = delete $args{ua} || LWP::UserAgent->new;
18 2   66     5776 my $base = $ENV{PLACK_TEST_EXTERNALSERVER_URI} || delete $args{uri};
19 2 50       58 $base = URI->new($base) if $base;
20              
21             $client->(sub {
22 2     2   561 my ($req) = shift->clone;
23              
24 2 50       1363 if ($base) {
25 2         112 my $uri = $req->uri->clone;
26 2         35 $uri->scheme($base->scheme);
27 2         314 $uri->host($base->host);
28 2         434 $uri->port($base->port);
29 2         165 $uri->path($base->path . $uri->path);
30 2         111 $req->uri($uri);
31             }
32              
33 2         75 return $ua->request($req);
34 2         15566 });
35             }
36              
37             1;
38              
39             __END__