line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Test::Agent; |
2
|
|
|
|
|
|
|
# git description: v1.3-1-g41fa5a5 |
3
|
|
|
|
|
|
|
$Plack::Test::Agent::VERSION = '1.4'; |
4
|
|
|
|
|
|
|
# ABSTRACT: OO interface for testing low-level Plack/PSGI apps |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
222388
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
370
|
|
7
|
8
|
|
|
8
|
|
62
|
use warnings; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
296
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
4276
|
use Test::TCP; |
|
8
|
|
|
|
|
505346
|
|
|
8
|
|
|
|
|
572
|
|
10
|
8
|
|
|
8
|
|
4295
|
use Plack::Loader; |
|
8
|
|
|
|
|
40862
|
|
|
8
|
|
|
|
|
248
|
|
11
|
8
|
|
|
8
|
|
5040
|
use HTTP::Response; |
|
8
|
|
|
|
|
163795
|
|
|
8
|
|
|
|
|
316
|
|
12
|
8
|
|
|
8
|
|
4668
|
use HTTP::Message::PSGI; |
|
8
|
|
|
|
|
12502
|
|
|
8
|
|
|
|
|
509
|
|
13
|
8
|
|
|
8
|
|
4639
|
use HTTP::Request::Common; |
|
8
|
|
|
|
|
25461
|
|
|
8
|
|
|
|
|
605
|
|
14
|
8
|
|
|
8
|
|
5298
|
use Test::WWW::Mechanize; |
|
8
|
|
|
|
|
856962
|
|
|
8
|
|
|
|
|
392
|
|
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
8
|
|
4672
|
use Plack::Util::Accessor qw( app host port server ua ); |
|
8
|
|
|
|
|
1768
|
|
|
8
|
|
|
|
|
55
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
10
|
|
|
10
|
1
|
10536
|
my ($class, %args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
10
|
|
|
|
|
36
|
my $self = bless {}, $class; |
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
|
|
86
|
$self->app( delete $args{app} ); |
25
|
10
|
|
|
|
|
154
|
$self->ua( delete $args{ua} ); |
26
|
10
|
|
50
|
|
|
123
|
$self->host( delete $args{host} || 'localhost' ); |
27
|
10
|
|
|
|
|
75
|
$self->port( delete $args{port} ); |
28
|
|
|
|
|
|
|
|
29
|
10
|
100
|
|
|
|
78
|
$self->start_server( delete $args{server} ) if $args{server}; |
30
|
|
|
|
|
|
|
|
31
|
10
|
|
|
|
|
179
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub start_server |
35
|
|
|
|
|
|
|
{ |
36
|
6
|
|
|
6
|
1
|
15
|
my ($self, $server_class) = @_; |
37
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
20
|
my $app = $self->app; |
39
|
6
|
|
|
|
|
39
|
my $host = $self->host; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $server = Test::TCP->new( |
42
|
|
|
|
|
|
|
code => sub |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
|
0
|
my $port = shift; |
45
|
0
|
|
|
|
|
0
|
my %args = ( host => $host, port => $port ); |
46
|
0
|
0
|
|
|
|
0
|
return $server_class |
47
|
|
|
|
|
|
|
? Plack::Loader->load( $server_class, %args )->run( $app ) |
48
|
|
|
|
|
|
|
: Plack::Loader->auto( %args )->run( $app ); |
49
|
|
|
|
|
|
|
}, |
50
|
6
|
|
|
|
|
99
|
); |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
161379
|
$self->port( $server->port ); |
53
|
6
|
50
|
|
|
|
224
|
$self->ua( $self->get_mech ) unless $self->ua; |
54
|
6
|
|
|
|
|
68
|
$self->server( $server ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub execute_request |
58
|
|
|
|
|
|
|
{ |
59
|
14
|
|
|
14
|
1
|
32
|
my ($self, $req) = @_; |
60
|
|
|
|
|
|
|
|
61
|
14
|
100
|
|
|
|
69
|
my $res = $self->server |
62
|
|
|
|
|
|
|
? $self->ua->request( $req ) |
63
|
|
|
|
|
|
|
: HTTP::Response->from_psgi( $self->app->( $req->to_psgi ) ); |
64
|
|
|
|
|
|
|
|
65
|
14
|
|
|
|
|
180734
|
$res->request( $req ); |
66
|
14
|
|
|
|
|
348
|
return $res; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get { |
70
|
12
|
|
|
12
|
1
|
21082
|
my ( $self, $uri, @args ) = @_; |
71
|
12
|
|
|
|
|
52
|
my $req = GET $self->normalize_uri($uri), @args; |
72
|
12
|
|
|
|
|
2289
|
return $self->execute_request($req); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub post |
76
|
|
|
|
|
|
|
{ |
77
|
2
|
|
|
2
|
1
|
12084
|
my ($self, $uri, @args) = @_; |
78
|
2
|
|
|
|
|
9
|
my $req = POST $self->normalize_uri($uri), @args; |
79
|
2
|
|
|
|
|
910
|
return $self->execute_request( $req ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub normalize_uri |
83
|
|
|
|
|
|
|
{ |
84
|
22
|
|
|
22
|
1
|
58
|
my ($self, $uri) = @_; |
85
|
22
|
|
|
|
|
492
|
my $normalized = URI->new( $uri ); |
86
|
22
|
|
|
|
|
42603
|
my $port = $self->port; |
87
|
|
|
|
|
|
|
|
88
|
22
|
100
|
|
|
|
321
|
$normalized->scheme( 'http' ) unless $normalized->scheme; |
89
|
22
|
100
|
|
|
|
28592
|
$normalized->host( 'localhost' ) unless $normalized->host; |
90
|
22
|
100
|
|
|
|
2673
|
$normalized->port( $port ) if $port; |
91
|
|
|
|
|
|
|
|
92
|
22
|
|
|
|
|
1126
|
return $normalized; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub get_mech |
96
|
|
|
|
|
|
|
{ |
97
|
8
|
|
|
8
|
1
|
2933
|
my $self = shift; |
98
|
8
|
|
|
|
|
70
|
return Test::WWW::Mechanize::Bound->new( |
99
|
|
|
|
|
|
|
bound_uri => $self->normalize_uri( '/' ) |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package |
104
|
|
|
|
|
|
|
Test::WWW::Mechanize::Bound; |
105
|
|
|
|
|
|
|
|
106
|
8
|
|
|
8
|
|
4127
|
use parent 'Test::WWW::Mechanize'; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
58
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub new |
109
|
|
|
|
|
|
|
{ |
110
|
8
|
|
|
8
|
|
51
|
my ($class, %args) = @_; |
111
|
8
|
|
|
|
|
35
|
my $bound_uri = delete $args{bound_uri}; |
112
|
8
|
|
|
|
|
225
|
my $self = $class->SUPER::new( %args ); |
113
|
8
|
|
|
|
|
97574
|
$self->bound_uri( $bound_uri ); |
114
|
8
|
|
|
|
|
98
|
return $self; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub bound_uri |
118
|
|
|
|
|
|
|
{ |
119
|
19
|
|
|
19
|
|
420
|
my ($self, $base_uri) = @_; |
120
|
19
|
100
|
|
|
|
98
|
$self->_elem( bound_uri => $base_uri ) if @_ == 2; |
121
|
19
|
|
|
|
|
118
|
return $self->_elem( 'bound_uri' ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub prepare_request |
125
|
|
|
|
|
|
|
{ |
126
|
11
|
|
|
11
|
|
56102
|
my $self = shift; |
127
|
11
|
|
|
|
|
24
|
my ($req) = @_; |
128
|
11
|
|
|
|
|
36
|
my $uri = $req->uri; |
129
|
11
|
|
|
|
|
75
|
my $base = $self->bound_uri; |
130
|
|
|
|
|
|
|
|
131
|
11
|
100
|
|
|
|
100
|
unless ($uri->scheme) |
132
|
|
|
|
|
|
|
{ |
133
|
2
|
|
|
|
|
31
|
$uri->scheme( $base->scheme ); |
134
|
2
|
|
|
|
|
135
|
$uri->host( $base->host ); |
135
|
2
|
|
|
|
|
171
|
$uri->port( $base->port ); |
136
|
|
|
|
|
|
|
} |
137
|
11
|
|
|
|
|
329
|
return $self->SUPER::prepare_request( @_ ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |