line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Object-Oriented PSGI Application Testing |
2
|
|
|
|
|
|
|
package Plack::Test::Simple; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
9292
|
use utf8; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
16
|
|
5
|
2
|
|
|
2
|
|
56
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
158
|
|
6
|
2
|
|
|
2
|
|
1686
|
use HTTP::Request; |
|
2
|
|
|
|
|
787564
|
|
|
2
|
|
|
|
|
85
|
|
7
|
2
|
|
|
2
|
|
6960
|
use HTTP::Response; |
|
2
|
|
|
|
|
19007
|
|
|
2
|
|
|
|
|
78
|
|
8
|
2
|
|
|
2
|
|
19
|
use URI; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
9
|
2
|
|
|
2
|
|
2968
|
use Moo; |
|
2
|
|
|
|
|
40136
|
|
|
2
|
|
|
|
|
12
|
|
10
|
2
|
|
|
2
|
|
6146
|
use Plack::Util; |
|
2
|
|
|
|
|
65700
|
|
|
2
|
|
|
|
|
65
|
|
11
|
2
|
|
|
2
|
|
1504
|
use Plack::Test::Simple::Transaction; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
216
|
|
12
|
2
|
|
|
2
|
|
23
|
use JSON qw(encode_json); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
21
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.000008'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BUILDARGS { |
18
|
1
|
|
|
1
|
0
|
12420
|
my ($class, @args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
50
|
33
|
|
|
16
|
unshift @args, 'psgi' if $args[0] && !$args[1]; |
21
|
1
|
|
|
|
|
27
|
return {@args}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has request => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
lazy => 1, |
28
|
|
|
|
|
|
|
builder => 1 |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_request { |
32
|
1
|
|
|
1
|
|
1798
|
return HTTP::Request->new( |
33
|
|
|
|
|
|
|
uri => URI->new(scheme => 'http', host => 'localhost', path => '/') |
34
|
|
|
|
|
|
|
) |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has psgi => ( |
39
|
|
|
|
|
|
|
is => 'rw', |
40
|
|
|
|
|
|
|
isa => sub { |
41
|
|
|
|
|
|
|
my $psgi = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
die 'The psgi attribute must must be a valid PSGI filepath or code '. |
44
|
|
|
|
|
|
|
'reference' if !$psgi && ('CODE' eq ref($psgi) xor -f $psgi); |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
coerce => sub { |
47
|
|
|
|
|
|
|
my $psgi = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# return psgi |
50
|
|
|
|
|
|
|
return $psgi if (ref $psgi) =~ /Plack::Test::/; # very trusting |
51
|
|
|
|
|
|
|
return Plack::Test->create($psgi) if 'CODE' eq ref $psgi; |
52
|
|
|
|
|
|
|
return Plack::Test->create(Plack::Util::load_psgi($psgi)); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub transaction { |
58
|
4
|
|
|
4
|
1
|
34085
|
my ($self, $meth, $path, $cont) = @_; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
122
|
my $trans = Plack::Test::Simple::Transaction->new( |
61
|
|
|
|
|
|
|
psgi => $self->psgi, |
62
|
|
|
|
|
|
|
request => $self->request->clone |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
50
|
|
|
8045
|
$meth ||= 'get'; |
66
|
4
|
|
50
|
|
|
20
|
$path ||= '/'; |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
1352
|
$trans->request->method(uc $meth); |
69
|
4
|
|
|
|
|
741
|
$trans->request->uri(URI->new($path)); |
70
|
|
|
|
|
|
|
|
71
|
4
|
100
|
|
|
|
4195
|
if (defined $cont) { |
72
|
2
|
100
|
|
|
|
49
|
$trans->request->content(ref $cont ? encode_json($cont) : $cont); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
4
|
|
|
|
|
104
|
return $trans; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub AUTOLOAD { |
88
|
3
|
|
|
3
|
|
74
|
my ($self, @args) = @_; |
89
|
3
|
|
|
|
|
37
|
my @cmds = split /_/, ($Plack::Test::Simple::AUTOLOAD =~ /.*::([^:]+)/)[0]; |
90
|
|
|
|
|
|
|
|
91
|
3
|
50
|
33
|
|
|
88
|
return $self->transaction($cmds[0], @args[0,1])->status_is( |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
92
|
|
|
|
|
|
|
$cmds[2], $args[2] |
93
|
|
|
|
|
|
|
) |
94
|
|
|
|
|
|
|
if @cmds == 3 |
95
|
|
|
|
|
|
|
&& $cmds[0] =~ /^(get|post|put|delete|head|options|connect|patch|trace)$/ |
96
|
|
|
|
|
|
|
&& $cmds[1] eq 'returns' |
97
|
|
|
|
|
|
|
&& $cmds[2] =~ /^\d{3}$/ |
98
|
|
|
|
|
|
|
; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
0
|
|
|
|
croak sprintf q(Can't locate object method "%s" via package "%s"), |
101
|
|
|
|
|
|
|
join('_', @cmds), ((ref $_[0] || $_[0]) || 'main') |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
|
|
sub DESTROY { |
105
|
|
|
|
|
|
|
# noop |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |