File Coverage

blib/lib/Plack/Test/Server.pm
Criterion Covered Total %
statement 36 40 90.0
branch 0 2 0.0
condition 3 7 42.8
subroutine 11 12 91.6
pod 0 3 0.0
total 50 64 78.1


line stmt bran cond sub pod time code
1             package Plack::Test::Server;
2 10     10   98 use strict;
  10         30  
  10         433  
3 10     10   50 use warnings;
  10         14  
  10         701  
4 10     10   86 use Carp;
  10         30  
  10         896  
5 10     10   510 use HTTP::Request;
  10         19070  
  10         339  
6 10     10   5524 use HTTP::Response;
  10         88348  
  10         425  
7 10     10   5141 use Test::TCP;
  10         823094  
  10         921  
8 10     10   5716 use Plack::Loader;
  10         48  
  10         424  
9 10     10   5014 use Plack::LWPish;
  10         45  
  10         3595  
10              
11             sub new {
12 11     11 0 46 my($class, $app, %args) = @_;
13              
14 11   50     93 my $host = $args{host} || '127.0.0.1';
15             my $server = Test::TCP->new(
16             listen => $args{listen},
17             host => $host,
18             code => sub {
19 0     0   0 my $sock_or_port = shift;
20             my $server = Plack::Loader->auto(
21             ($args{listen} ? (
22 0 0       0 listen_sock => $sock_or_port,
23             ):(
24             port => $sock_or_port,
25             host => $host,
26             ))
27             );
28 0         0 $server->run($app);
29 0         0 exit;
30             },
31 11         191 );
32              
33 11         713563 bless { server => $server, %args }, $class;
34             }
35              
36             sub port {
37 15     15 0 206 my $self = shift;
38 15         214 $self->{server}->port;
39             }
40              
41             sub request {
42 15     15 0 65 my($self, $req) = @_;
43              
44 15   33     706 my $ua = $self->{ua} || Plack::LWPish->new( no_proxy => [qw/127.0.0.1/] );
45              
46 15         165 $req->uri->scheme('http');
47 15   50     35900 $req->uri->host($self->{host} || '127.0.0.1');
48 15         5572 $req->uri->port($self->port);
49              
50 15         4123 return $ua->request($req);
51             }
52              
53             1;
54              
55             __END__