blib/lib/Punk/Test.pm

filter: Statementstmt 100% 701 / 711 (10 uncoverable) Branchbran 90.1% 281 / 346 (63 uncoverable) Conditioncond 97.3% 126 / 188 (61 uncoverable) MC/DCmcdc 98.0% 40 / 104 (62 uncoverable) Subroutinesub 100% 84 / 84 Podpod 100% 42 / 42 totaltotal 97.2% 1274 / 1475 (196 uncoverable) CC 269 SCAR 23.0
CC
269
Cov
97%
_build_env
30.0
_multipart_input
27.3
websocket_ok
14.0
CRAP 10.0
« blib/lib/Punk/Test/WS.pm ↑ Summary blib/lib/Punk/Plugin/I18n.pm »
1 package Punk::Test;
2  
3 56 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 56 our $VERSION = '0.70';
8  
9 56 ▶use Test::Builder ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 56 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 56 ▶use Socket qw(AF_UNIX SOCK_STREAM PF_UNSPEC);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 56 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 56 ▶use File::Raw::JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 56 ▶use File::Raw::XML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 56 ▶use Punk::Test::WS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 56 ▶use Punk::Test::WS::Conn ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # An in-process test client for a compiled Punk application: one object is
19 # one browser - it keeps a cookie jar, so sessions, CSRF and flash flows
20 # test the way they run. Every assertion returns $self for chaining and
21 # reports through the one Test::Builder singleton, so it works under
22 # Test::More and Test2 alike.
23  
24 56 my $TB = Test::Builder->new;
25 56 my %APPS;
26  
27 # An application under test runs in the `test` environment unless something
28 # already said which. It is where a 500 still says what the handler died
29 # with: in production that goes to the log and the body is a fixed message,
30 # and an assertion cannot read a log.
31 56 ▶$ENV{PUNK_ENV} = 'test' unless defined $ENV{PUNK_ENV};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"PUNK_ENV"} 52 4 56
32  
33 178 ▶sub new {
Subroutine new: called CC=11 SCAR=24.2
Pod documented
34 178 my ($class, $app, %opts) = @_;
35 178 ▶ my $app_class = ref $app ? undef : $app;
Branch: 1 branch
BranchTrueFalseTotal
ref $app ? : 26 152 178
36 178 ▶ if (ref $app ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $app ne "CODE") 152 26 178
37 152 my $name = $app;
38 152 ▶ unless ($name->can('to_app')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name->can("to_app")) 1 151 152
39 # uncoverable branch false
40 1 ▶ eval "require $name"
Branch: 1 branch
BranchTrueFalseTotal
eval "require $name" or die "Punk::Test: could not load ${name}: $@" 0 1 1
41 or die "Punk::Test: could not load $name: $@";
42 }
43 # uncoverable branch true
44 151 ▶ $name->can('to_app')
Branch: 1 branch
BranchTrueFalseTotal
$name->can("to_app") or die "Punk::Test: $name has no to_app - not a Punk app?\n" 151 0 151
45 or die "Punk::Test: $name has no to_app - not a Punk app?\n";
46 # to_app compiles once per class, and two clients against one app
47 # (two browsers, one server) is a thing tests want - so the frozen
48 # coderef is shared
49 # uncoverable condition false
50 151 ▶ $app = $APPS{$name} //= $name->to_app;
Condition100%2/3
$APPS{$name} //= $name->to_app
l!l&&r!l&&!r
411100
MC/DC100%0/2
$APPS{$name} //= $name->to_app
$APPS{$name} $name->to_app
Truth table100%2/3
A //= B
A= $APPS{$name}B= $name->to_app
ABresult
1X1
011
000
51 }
52 return bless {
53 app => $app,
54 class => $app_class,
55 jar => {},
56 headers => {},
57 timeout => $opts{timeout} // 5,
58 max_bytes => $opts{max_bytes} // 1_000_000,
59 csrf_cookie => $opts{csrf_cookie} // 'csrf',
60 # uncoverable condition left count:2
61 # uncoverable condition left count:3
62 # uncoverable condition left count:4
63 177 ▶ csrf_header => $opts{csrf_header} // 'X-CSRF-Token',
Condition100%5/8
$opts{"timeout"} // 5
l!l
5172
$opts{"max_bytes"} // 1000000
l!l
0177
$opts{"csrf_cookie"} // "csrf"
l!l
0177
$opts{"csrf_header"} // "X-CSRF-Token"
l!l
0177
MC/DC100%1/1
$opts{"timeout"} // 5
$opts{"timeout"}
MC/DC100%0/1
$opts{"max_bytes"} // 1000000
$opts{"max_bytes"}
MC/DC100%0/1
$opts{"csrf_cookie"} // "csrf"
$opts{"csrf_cookie"}
MC/DC100%0/1
$opts{"csrf_header"} // "X-CSRF-Token"
$opts{"csrf_header"}
Truth table100%2/2
A
A= $opts{"timeout"}
Aresult
11
00
Truth table100%1/2
A
A= $opts{"max_bytes"}
Aresult
11
00
Truth table100%1/2
A
A= $opts{"csrf_cookie"}
Aresult
11
00
Truth table100%1/2
A
A= $opts{"csrf_header"}
Aresult
11
00
64 res => undef,
65 }, $class;
66 }
67  
68 # ---- requests ----------------------------------------------------------------
69  
70 415 ▶sub get_ok { my $self = shift; $self->_request_ok('GET', @_) }
Subroutine get_ok: called CC=1 SCAR=0.0
Pod documented
71 140 ▶sub post_ok { my $self = shift; $self->_request_ok('POST', @_) }
Subroutine post_ok: called CC=1 SCAR=0.0
Pod documented
72 3 ▶sub put_ok { my $self = shift; $self->_request_ok('PUT', @_) }
Subroutine put_ok: called CC=1 SCAR=0.0
Pod documented
73 7 ▶sub patch_ok { my $self = shift; $self->_request_ok('PATCH', @_) }
Subroutine patch_ok: called CC=1 SCAR=0.0
Pod documented
74 5 ▶sub delete_ok { my $self = shift; $self->_request_ok('DELETE', @_) }
Subroutine delete_ok: called CC=1 SCAR=0.0
Pod documented
75 4 ▶sub head_ok { my $self = shift; $self->_request_ok('HEAD', @_) }
Subroutine head_ok: called CC=1 SCAR=0.0
Pod documented
76 5 ▶sub options_ok { my $self = shift; $self->_request_ok('OPTIONS', @_) }
Subroutine options_ok: called CC=1 SCAR=0.0
Pod documented
77 19 ▶sub request_ok { my $self = shift; $self->_request_ok(@_) }
Subroutine request_ok: called CC=1 SCAR=0.0
Pod documented
78  
79 # Sign a user straight into the jar - the signed session cookie is minted
80 # through the app's own session config, so tests reach guarded pages without
81 # driving a login flow first. Takes an id or a user row; needs a client
82 # built from a class name (the app object holds the session secret).
83 4 ▶sub login_as {
Subroutine login_as: called CC=8 SCAR=20.8
Pod documented
84 4 my ($self, $user) = @_;
85 my $class = $self->{class}
86 4 ▶ or die "Punk::Test: login_as needs a client built from a class "
Branch: 1 branch
BranchTrueFalseTotal
my $class = $self->{"class"} or die "Punk::Test: login_as needs a client built from a class name, not a coderef\n" 3 1 4
87 . "name, not a coderef\n";
88 3 my $app = $class->punk_app;
89 3 ▶ my $auth = $app->{auth} || {};
Condition100%2/2
$app->{'auth'} || {}
l!l
21
MC/DC100%1/1
$app->{'auth'} || {}
$app->{'auth'}
Truth table100%2/2
A
A= $app->{'auth'}
Aresult
11
00
90 3 ▶ my $key = $auth->{session_key} // 'user_id';
Condition100%2/2
$auth->{"session_key"} // "user_id"
l!l
21
MC/DC100%1/1
$auth->{"session_key"} // "user_id"
$auth->{"session_key"}
Truth table100%2/2
A
A= $auth->{"session_key"}
Aresult
11
00
91 3 ▶ my $idf = ($auth->{fields} || {})->{id} // 'id';
Condition100%4/4
+($auth->{"fields"} || {})->{"id"} // "id"
l!l
21
$auth->{'fields'} || {}
l!l
21
MC/DC100%1/1
+($auth->{"fields"} || {})->{"id"} // "id"
$auth->{'fields'}
Truth table100%2/2
A
A= $auth->{'fields'}
Aresult
11
00
92 3 ▶ my $id = ref $user eq 'HASH' ? $user->{$idf} : $user;
Branch: 1 branch
BranchTrueFalseTotal
ref $user eq 'HASH' ? : 1 2 3
93 # uncoverable branch true
94 3 ▶ defined $id or die "Punk::Test: login_as needs a user row or id\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $id or die "Punk::Test: login_as needs a user row or id\n" 3 0 3
95 # _seal_session, not _seal: an application with `session store => ...`
96 # keeps the payload server-side, so a cookie with the session sealed into
97 # it is no session at all there. This writes it wherever the application
98 # will look.
99 3 my ($name, $value) = Punk::Session::_seal_session($app, { $key => $id });
100 3 $self->{jar}{$name} = $value;
101 3 return $self;
102 }
103  
104 # A header on every request from here on, the way the jar holds a cookie:
105 # a credential a client carries, an Accept a whole file's worth of requests
106 # needs. undef removes one; no arguments gives back the lot.
107 #
108 # $t->request_header(Authorization => "Bearer $key");
109 # $t->request_header(Authorization => undef);
110 #
111 # A request's own `headers` still wins, so one call can be made an exception
112 # without unsetting and setting again around it. Named for the request side
113 # because `header` is the last response's, and one name for both directions
114 # is how a test comes to assert what it just sent.
115 7 ▶sub request_header {
Subroutine request_header: called CC=4 SCAR=13.9
Pod documented
116 7 my ($self, %h) = @_;
117 7 ▶ return { %{ $self->{headers} } } unless %h;
Branch: 1 branch
BranchTrueFalseTotal
unless %h 1 6 7
118 6 for my $k (keys %h) {
119 7 ▶ if (defined $h{$k}) { $self->{headers}{$k} = $h{$k} }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h{$k}) { } 6 1 7
120 1 else { delete $self->{headers}{$k} }
121 }
122 6 return $self;
123 }
124  
125 184 ▶sub _urlenc {
Subroutine _urlenc: called CC=3 SCAR=11.0
126 184 my ($s) = @_;
127 # uncoverable branch true
128 184 ▶ $s = '' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 184 184
129 # uncoverable branch true
130 184 ▶ utf8::encode($s) if utf8::is_utf8($s);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($s) 0 184 184
131 184 $s =~ s/([^A-Za-z0-9_.~-])/sprintf '%%%02X', ord $1/ge;
132 184 return $s;
133 }
134  
135 # A path, or [ 'book', id => 1 ] naming a route.
136 #
137 # This is what turns a wrong route name into a failing test rather than a
138 # 404 in production: url_for croaks on a name no route carries, and the
139 # croak arrives here, at the request that named it.
140 693 ▶sub _resolve_path {
Subroutine _resolve_path: called CC=6 SCAR=18.0
141 693 my ($self, $path) = @_;
142 693 ▶ return $path unless ref $path eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $path eq "ARRAY" 687 6 693
143 6 my ($name, @args) = @$path;
144 my $class = $self->{class}
145 6 ▶ or die "Punk::Test: [ '$name', ... ] names a route, which needs the "
Branch: 1 branch
BranchTrueFalseTotal
my $class = $self->{"class"} or die "Punk::Test: [ '${name}', ... ] names a route, which needs the " . 'application class - construct the client with ' . "Punk::Test->new('MyApp') rather than with a coderef\n" 5 1 6
146 . "application class - construct the client with "
147 . "Punk::Test->new('MyApp') rather than with a coderef\n";
148 # uncoverable branch false
149 5 ▶ my $app = $class->can('punk_app') ? $class->punk_app : undef;
Branch: 1 branch
BranchTrueFalseTotal
$class->can('punk_app') ? : 5 0 5
150 # uncoverable branch true
151 # uncoverable condition left
152 # uncoverable condition right
153 5 ▶ $app && $app->can('url_for')
Branch: 1 branch
BranchTrueFalseTotal
$app and $app->can("url_for") or die "Punk::Test: [ '${name}', ... ] needs Punk 0.31 or newer\n" 5 0 5
Condition100%1/3
$app and $app->can("url_for")
!ll&&!rl&&r
005
MC/DC100%0/2
$app and $app->can("url_for")
$app $app->can("url_for")
Truth table100%1/3
A and B
A= $appB= $app->can("url_for")
ABresult
0X0
100
111
154 or die "Punk::Test: [ '$name', ... ] needs Punk 0.31 or newer\n";
155 5 return $app->url_for($name, @args);
156 }
157  
158 633 ▶sub _build_env {
Subroutine _build_env: called CC=30 SCAR=34.0
159 633 my ($self, $method, $path, %o) = @_;
160 633 ▶ my $query = $o{query} // '';
Condition100%2/2
$o{"query"} // ""
l!l
1632
MC/DC100%1/1
$o{"query"} // ""
$o{"query"}
Truth table100%2/2
A
A= $o{"query"}
Aresult
11
00
161 633 ▶ ($path, $query) = ($1, $2) if !length $query && $path =~ /\A([^?]*)\?(.*)\z/s;
Branch: 1 branch
BranchTrueFalseTotal
if not length $query and $path =~ /\A([^?]*)\?(.*)\z/s 12 621 633
Condition100%3/3
not length $query and $path =~ /\A([^?]*)\?(.*)\z/s
!ll&&!rl&&r
162012
MC/DC100%2/2
not length $query and $path =~ /\A([^?]*)\?(.*)\z/s
not length $query $path =~ /\A([^?]*)\?(.*)\z/s
Truth table100%3/3
not(A) and B
A= not length $queryB= $path =~ /\A([^?]*)\?(.*)\z/s
ABresult
0X0
100
111
162  
163 633 my ($body, $type) = ('', $o{type});
164 633 my ($in, $clen);
165 633 ▶ if (exists $o{upload}) {
Branch: 5 branches
BranchTrueFalseTotal
if (exists $o{'upload'}) { } 24 609 633
elsif (exists $o{'json'}) { } 20 589 609
elsif (exists $o{'xml'}) { } 7 582 589
elsif (exists $o{'form'}) { } 52 530 582
elsif (defined $o{'body'}) { } 16 514 530
166 24 for my $k (qw(json xml body type)) {
167 die "Punk::Test: upload and $k do not combine - an upload "
168 90 ▶ . "is multipart/form-data\n" if exists $o{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o{$k} 4 86 90
169 }
170 20 ($in, $clen, $type) = $self->_multipart_input($o{form}, $o{upload});
171 }
172 elsif (exists $o{json}) {
173 20 $body = File::Raw::JSON::file_json_encode($o{json});
174 # uncoverable condition left
175 20 ▶ $type //= 'application/json';
Condition100%1/2
$type //= "application/json"
l!l
020
MC/DC100%0/1
$type //= "application/json"
$type
Truth table100%1/2
A
A= $type
Aresult
11
00
176 }
177 elsif (exists $o{xml}) {
178 # a Document or Node serialises itself; anything else is markup the
179 # caller wrote, including the malformed strings a test wants to send
180 7 ▶ $body = ref $o{xml} ? $o{xml}->to_string : $o{xml};
Branch: 1 branch
BranchTrueFalseTotal
ref $o{'xml'} ? : 1 6 7
181 # uncoverable condition left
182 7 ▶ $type //= 'application/xml';
Condition100%1/2
$type //= "application/xml"
l!l
07
MC/DC100%0/1
$type //= "application/xml"
$type
Truth table100%1/2
A
A= $type
Aresult
11
00
183 }
184 elsif (exists $o{form}) {
185 52 my $f = $o{form};
186 52 $body = join '&', map { _urlenc($_) . '=' . _urlenc($f->{$_}) }
187 sort keys %$f;
188 # uncoverable condition left
189 52 ▶ $type //= 'application/x-www-form-urlencoded';
Condition100%1/2
$type //= "application/x-www-form-urlencoded"
l!l
052
MC/DC100%0/1
$type //= "application/x-www-form-urlencoded"
$type
Truth table100%1/2
A
A= $type
Aresult
11
00
190 }
191 elsif (defined $o{body}) {
192 16 $body = $o{body};
193 }
194  
195 627 ▶ unless ($in) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in) 609 18 627
196 # uncoverable branch true
197 609 ▶ open $in, '<', \$body or die "Punk::Test: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", \$body or die "Punk::Test: $!" 609 0 609
198 609 ▶ $clen = length $body if length $body or defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if length $body or defined $type 95 514 609
Condition100%3/3
length $body or defined $type
l!l&&r!l&&!r
941514
MC/DC100%2/2
length $body or defined $type
length $body defined $type
Truth table100%3/3
A or B
A= length $bodyB= defined $type
ABresult
1X1
011
000
199 }
200 627 my $env = {
201 REQUEST_METHOD => $method,
202 PATH_INFO => $path,
203 QUERY_STRING => $query,
204 SERVER_NAME => 'localhost',
205 SERVER_PORT => 80,
206 SERVER_PROTOCOL => 'HTTP/1.1',
207 HTTP_HOST => 'localhost',
208 'psgi.url_scheme' => 'http',
209 'psgi.input' => $in,
210 'psgi.errors' => \*STDERR,
211 'psgi.version' => [ 1, 1 ],
212 'psgi.streaming' => 1,
213 };
214 627 ▶ if (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clen) 113 514 627
215 113 $env->{CONTENT_LENGTH} = $clen;
216 # uncoverable condition right
217 113 ▶ $env->{CONTENT_TYPE} = $type // '';
Condition100%1/2
$type // ""
l!l
1130
MC/DC100%0/1
$type // ""
$type
Truth table100%1/2
A
A= $type
Aresult
11
00
218 }
219 # Sticky headers first, so a single request's `headers` can still override
220 # one of them - the narrower statement wins, as it does everywhere else.
221 627 for my $h ($self->{headers}, $o{headers}) {
222 1254 ▶ next unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 454 800 1254
223 800 for my $k (keys %$h) {
224 340 my $ek = uc $k;
225 340 $ek =~ tr/-/_/;
226 # uncoverable branch false
227 # uncoverable condition left
228 # uncoverable condition right
229 340 ▶ $ek = "HTTP_$ek"
Branch: 1 branch
BranchTrueFalseTotal
unless $ek eq "CONTENT_TYPE" or $ek eq "CONTENT_LENGTH" 340 0 340
Condition100%1/3
$ek eq "CONTENT_TYPE" or $ek eq "CONTENT_LENGTH"
l!l&&r!l&&!r
00340
MC/DC100%0/2
$ek eq "CONTENT_TYPE" or $ek eq "CONTENT_LENGTH"
$ek eq "CONTENT_TYPE" $ek eq "CONTENT_LENGTH"
Truth table100%1/3
A or B
A= $ek eq "CONTENT_TYPE"B= $ek eq "CONTENT_LENGTH"
ABresult
1X1
011
000
230 unless $ek eq 'CONTENT_TYPE' || $ek eq 'CONTENT_LENGTH';
231 340 $env->{$ek} = $h->{$k};
232 }
233 }
234 627 ▶ if ($o{csrf}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"csrf"}) 11 616 627
235 11 my $tok = $self->csrf_token;
236 11 ▶ if (defined $tok) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tok) { } 4 7 11
237 4 my $ek = uc $self->{csrf_header};
238 4 $ek =~ tr/-/_/;
239 4 $env->{"HTTP_$ek"} = $tok;
240 }
241 else {
242 7 $TB->diag("csrf => 1, but the jar holds no "
243 . "'$self->{csrf_cookie}' cookie yet - GET a page first");
244 }
245 }
246 627 ▶ if (my $jar = $self->_jar_header) { $env->{HTTP_COOKIE} = $jar }
Branch: 1 branch
BranchTrueFalseTotal
if (my $jar = $self->_jar_header) 102 525 627
247 627 ▶ %$env = (%$env, %{ $o{env} }) if $o{env};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"env"} 52 575 627
248 627 return $env;
249 }
250  
251 # ---- multipart ---------------------------------------------------------------
252  
253 # The `upload` option: form pairs and upload specs encoded as
254 # multipart/form-data. The body is never assembled - the parts become a
255 # list of items (header strings whole, file parts read a buffer at a
256 # time) drained through psgi.input - so a test of the server's spill
257 # path costs this process one read buffer, not the file.
258  
259 56 my @_BND = ('0' .. '9', 'A' .. 'Z', 'a' .. 'z');
260 17 ▶sub _mp_boundary { join '', 'PunkTest', map { $_BND[int rand @_BND] } 1 .. 16 }
Subroutine _mp_boundary: called CC=1 SCAR=0.0
261  
262 # A name or filename into a Content-Disposition quoted-string: quotes and
263 # newlines percent-encoded, everything else (UTF-8 included) sent raw,
264 # which is RFC 7578 and what browsers do. The server-side parser stores
265 # what arrives; it does not decode.
266 53 ▶sub _mp_name {
Subroutine _mp_name: called CC=3 SCAR=11.0
267 53 my ($s) = @_;
268 # uncoverable branch true
269 53 ▶ $s = '' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 53 53
270 53 ▶ utf8::encode($s) if utf8::is_utf8($s);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($s) 1 52 53
271 53 $s =~ s/(["\r\n])/sprintf '%%%02X', ord $1/ge;
272 53 return $s;
273 }
274  
275 # Whether one content source contains the boundary. A file is scanned in
276 # chunks with a boundary-length overlap, because the hit this exists to
277 # catch is exactly the one that straddles a read.
278 32 ▶sub _mp_contains {
Subroutine _mp_contains: called CC=6 SCAR=18.0
279 32 my ($src, $bnd) = @_;
280 32 ▶ return index($$src, $bnd) >= 0 if ref $src;
Branch: 1 branch
BranchTrueFalseTotal
if ref $src 30 2 32
281 # uncoverable branch true
282 2 ▶ open my $fh, '<:raw', $src or die "Punk::Test: cannot open '$src': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $src or die "Punk::Test: cannot open '${src}': $!" 2 0 2
283 2 my ($tail, $keep) = ('', length($bnd) - 1);
284 2 ▶ while (read $fh, my $chunk, 65536) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $chunk, 65536) 5 2 7
285 5 $chunk = $tail . $chunk;
286 # uncoverable branch true
287 5 ▶ return 1 if index($chunk, $bnd) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($chunk, $bnd) != -1 0 5 5
288 5 ▶ $tail = length $chunk > $keep ? substr($chunk, -$keep) : $chunk;
Branch: 1 branch
BranchTrueFalseTotal
length $chunk > $keep ? : 4 1 5
289 }
290 2 return 0;
291 }
292  
293 20 ▶sub _multipart_input {
Subroutine _multipart_input: called CC=27 SCAR=33.1
294 20 my ($self, $form, $upload) = @_;
295 # uncoverable branch true
296 20 ▶ die "Punk::Test: upload takes a hashref of field => arrayref\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $upload eq "HASH" 0 20 20
297 unless ref $upload eq 'HASH';
298 20 my (@parts, @scan);
299 20 ▶ for my $k (sort keys %{ $form || {} }) {
Condition100%2/2
$form || {}
l!l
911
MC/DC100%1/1
$form || {}
$form
Truth table100%2/2
A
A= $form
Aresult
11
00
300 9 my $val = $form->{$k};
301 # uncoverable branch true
302 9 ▶ $val = '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 9 9
303 # uncoverable branch true
304 9 ▶ utf8::encode($val) if utf8::is_utf8($val);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($val) 0 9 9
305 9 push @parts, { name => $k, content => $val };
306 9 push @scan, \$val;
307 }
308 20 for my $field (sort keys %$upload) {
309 22 my $v = $upload->{$field};
310 # uncoverable condition right
311 22 ▶ die "Punk::Test: upload => { $field => ... } takes an arrayref: "
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" and @$v 1 21 22
Condition100%2/3
ref $v eq "ARRAY" and @$v
!ll&&!rl&&r
1021
MC/DC100%1/2
ref $v eq "ARRAY" and @$v
ref $v eq "ARRAY" @$v
Truth table100%2/3
A and B
A= ref $v eq "ARRAY"B= @$v
ABresult
0X0
100
111
312 . "a path or a scalar ref of content, then optional filename "
313 . "and type\n" unless ref $v eq 'ARRAY' && @$v;
314 21 ▶ for my $spec (ref $v->[0] eq 'ARRAY' ? @$v : $v) {
Branch: 1 branch
BranchTrueFalseTotal
ref $v->[0] eq 'ARRAY' ? : 2 19 21
315 23 my ($src, $fname, $ftype) = @$spec;
316 23 ▶ my %p = (name => $field,
Condition100%2/2
$ftype // "application/octet-stream"
l!l
815
MC/DC100%1/1
$ftype // "application/octet-stream"
$ftype
Truth table100%2/2
A
A= $ftype
Aresult
11
00
317 type => $ftype // 'application/octet-stream');
318 23 ▶ if (ref $src eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src eq 'SCALAR') { } 20 3 23
319 # uncoverable condition right
320 20 ▶ my $bytes = $$src // '';
Condition100%1/2
$$src // ""
l!l
200
MC/DC100%0/1
$$src // ""
$$src
Truth table100%1/2
A
A= $$src
Aresult
11
00
321 # uncoverable branch true
322 20 ▶ utf8::encode($bytes) if utf8::is_utf8($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($bytes) 0 20 20
323 20 $p{content} = $bytes;
324 # uncoverable condition false
325 20 ▶ $p{filename} = $fname // $field;
Condition100%2/3
$fname // $field
l!l&&r!l&&!r
1820
MC/DC100%0/2
$fname // $field
$fname $field
Truth table100%2/3
A // B
A= $fnameB= $field
ABresult
1X1
011
000
326 20 push @scan, \$bytes;
327 }
328 else {
329 # uncoverable condition right count:1
330 # uncoverable condition left count:2
331 3 ▶ die "Punk::Test: upload => { $field => ... }: no file at '"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $src and -f $src 1 2 3
Condition20%3/5
defined $src and -f $src
!ll&&!rl&&r
012
$src // ""
l!l
10
MC/DC50%1/2
defined $src and -f $src
defined $src -f $src
MC/DC100%0/1
$src // ""
$src
Truth table33%2/3
A and B
A= defined $srcB= -f $src
ABresult
0X0
100
111
Truth table0%1/2
A
A= $src
Aresult
11
00
332 . ($src // '') . "'\n" unless defined $src && -f $src;
333 2 $p{path} = $src;
334 2 $p{size} = -s $src;
335 # uncoverable condition false
336 2 ▶ $p{filename} = $fname // ($src =~ m{([^/\\]+)\z})[0];
Condition100%2/3
$fname // ($src =~ m(([^/\\]+)\z))[0]
l!l&&r!l&&!r
110
MC/DC100%0/2
$fname // ($src =~ m(([^/\\]+)\z))[0]
$fname ($src =~ m(([^/\\]+)\z))[0]
Truth table100%2/3
A // B
A= $fnameB= ($src =~ m(([^/\\]+)\z))[0]
ABresult
1X1
011
000
337 2 push @scan, $src;
338 }
339 22 push @parts, \%p;
340 }
341 }
342  
343 # The boundary must not appear in any part. Verified, not hoped:
344 # scanning also proves every named file readable before the request
345 # starts, so a bad path fails here and not as a truncated body.
346 18 my $bnd = _mp_boundary();
347 18 ▶ for (my $tries = 1; grep { _mp_contains($_, $bnd) } @scan; $tries++) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {_mp_contains($_, $bnd);} @scan) 1 18 19
348 # uncoverable branch true
349 1 ▶ die "Punk::Test: could not pick a boundary absent from the "
Branch: 1 branch
BranchTrueFalseTotal
if $tries >= 16 0 1 1
350 . "content\n" if $tries >= 16;
351 1 $bnd = _mp_boundary();
352 }
353  
354 18 my ($len, @items) = (0);
355 18 for my $p (@parts) {
356 my $hdr = "--$bnd\r\nContent-Disposition: form-data; name=\""
357 31 . _mp_name($p->{name}) . '"';
358 31 ▶ if (exists $p->{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"filename"}) 22 9 31
359 22 $hdr .= '; filename="' . _mp_name($p->{filename}) . '"'
360 . "\r\nContent-Type: $p->{type}";
361 }
362 31 $hdr .= "\r\n\r\n";
363 31 ▶ if (defined $p->{path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p->{'path'}) { } 2 29 31
364 open my $fh, '<:raw', $p->{path}
365 # uncoverable branch true
366 2 ▶ or die "Punk::Test: cannot open '$p->{path}': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $p->{"path"} or die qq[Punk::Test: cannot open '$p->{"path"}': $!] 2 0 2
367 2 push @items, $hdr, { fh => $fh };
368 2 $len += $p->{size};
369 }
370 else {
371 29 push @items, $hdr, $p->{content};
372 29 $len += length $p->{content};
373 }
374 31 push @items, "\r\n";
375 31 $len += length($hdr) + 2;
376 }
377 18 push @items, "--$bnd--\r\n";
378 18 $len += length $items[-1];
379  
380 18 push @Punk::Test::_MPInput::QUEUE, \@items;
381 # uncoverable branch true
382 18 ▶ open my $in, '<:via(Punk::Test::_MPInput)', \(my $empty = '')
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<:via(Punk::Test::_MPInput)", \(my $empty = "") or die "Punk::Test: $!" 18 0 18
383 or die "Punk::Test: $!";
384 18 return ($in, $len, "multipart/form-data; boundary=$bnd");
385 }
386  
387 598 ▶sub _request_ok {
Subroutine _request_ok: called CC=7 SCAR=19.5
388 598 my ($self, $method, $path, %o) = @_;
389 598 local $Test::Builder::Level = $Test::Builder::Level + 2;
390 598 $path = $self->_resolve_path($path);
391 595 my $env = $self->_build_env($method, $path, %o);
392 589 my $r = eval { $self->{app}->($env) };
393 589 my $err = $@;
394 589 ▶ if (ref $r eq 'CODE') { # a psgi.streaming response
Branch: 1 branch
BranchTrueFalseTotal
if (ref $r eq "CODE") 20 569 589
395 20 $r = eval { $self->_drive_streaming($r) };
396 # uncoverable condition left
397 # uncoverable condition right
398 20 ▶ $err ||= $@;
Condition100%1/3
$err ||= $@
l!l&&r!l&&!r
0020
MC/DC100%0/2
$err ||= $@
$err $@
Truth table100%1/3
A ||= B
A= $errB= $@
ABresult
1X1
011
000
399 }
400 589 ▶ if (ref $r eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $r eq 'ARRAY') { } 583 6 589
401 583 $self->_set_response($r);
402 # uncoverable condition false
403 583 ▶ $TB->ok(1, $o{name} // "$method $path");
Condition100%2/2
$o{"name"} // "$method $path"
l!l
60523
MC/DC100%1/1
$o{"name"} // "$method $path"
$o{"name"}
Truth table100%2/2
A
A= $o{"name"}
Aresult
11
00
404 }
405 else {
406 6 $self->{res} = undef;
407 # uncoverable condition left
408 # uncoverable condition false
409 6 ▶ $TB->ok(0, $o{name} // "$method $path");
Condition100%1/2
$o{"name"} // "$method $path"
l!l
06
MC/DC100%0/1
$o{"name"} // "$method $path"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
Aresult
11
00
410 6 ▶ $TB->diag($err ? "the application died: $err"
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 3 3 6
411 : 'the application did not return a PSGI response');
412 }
413 589 return $self;
414 }
415  
416 # Drive a delayed-response coderef to completion, collecting the writes.
417 49 ▶sub _drive_streaming {
Subroutine _drive_streaming: called CC=2 SCAR=6.9
418 49 my ($self, $code) = @_;
419 49 my ($status, $headers, @writes, $closed);
420 49 my $max = $self->{max_bytes};
421 49 my $got = 0;
422 103 ▶ my $writer = Punk::Test::_Writer->new(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
423 103 $got += length $_[0];
424 # uncoverable branch true
425 103 ▶ die "Punk::Test: stream exceeded $max bytes without closing\n"
Branch: 1 branch
BranchTrueFalseTotal
if $got > $max 0 103 103
426 if $got > $max;
427 103 push @writes, $_[0];
428 49 }, \$closed);
429 49 ▶ my $ret = $code->(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
430 49 my ($triplet) = @_;
431 49 ($status, $headers) = @$triplet[0, 1];
432 49 ▶ return $writer if @$triplet < 3;
Branch: 1 branch
BranchTrueFalseTotal
if @$triplet < 3 42 7 49
433 7 push @writes, @{ $triplet->[2] };
434 7 $closed = 1;
435 7 return;
436 49 });
437 # uncoverable condition right
438 49 ▶ return [ $status, $headers // [], [ join '', @writes ] ];
Condition100%1/2
$headers // []
l!l
490
MC/DC100%0/1
$headers // []
$headers
Truth table100%1/2
A
A= $headers
Aresult
11
00
439 }
440  
441 615 ▶sub _set_response {
Subroutine _set_response: called CC=12 SCAR=24.9
442 615 my ($self, $r) = @_;
443 615 my $body = $r->[2];
444 # uncoverable condition right
445 615 ▶ if (ref $body eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $body eq 'ARRAY') { } 590 25 615
elsif (builtin::blessed($body) and $body->can('getline')) { } 8 17 25
446 590 $body = join '', grep { defined } @$body;
447 }
448 ▶ elsif (Scalar::Util::blessed($body) && $body->can('getline')) {
Condition66%2/3
builtin::blessed($body) and $body->can("getline")
!ll&&!rl&&r
1708
MC/DC50%1/2
builtin::blessed($body) and $body->can("getline")
builtin::blessed($body) $body->can("getline")
Truth table66%2/3
A and B
A= builtin::blessed($body)B= $body->can("getline")
ABresult
0X0
100
111
449 8 my @chunks; # a PSGI body object (send_file)
450 8 ▶ while (defined(my $chunk = $body->getline)) { push @chunks, $chunk }
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $chunk = $body->getline)) 9 8 17
451 8 eval { $body->close };
452 8 $body = join '', @chunks;
453 }
454 else { # a filehandle (Punk::Static)
455 17 local $/;
456 17 my $fh = $body;
457 # uncoverable condition right
458 17 ▶ $body = <$fh> // '';
Condition100%1/2
readline $fh // ""
l!l
170
MC/DC100%0/1
readline $fh // ""
readline $fh
Truth table100%1/2
A
A= readline $fh
Aresult
11
00
459 17 eval { $fh->close };
460 }
461 615 $self->{res} = { status => $r->[0], headers => $r->[1], body => $body };
462 615 delete $self->{$_} for qw(json xml);
463 615 my @h = @{ $r->[1] };
464 615 ▶ while (my ($k, $v) = splice @h, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@h, 0, 2)) 1541 615 2156
465 1541 ▶ next unless lc $k eq 'set-cookie';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $k eq "set-cookie" 1453 88 1541
466 # uncoverable branch true
467 88 ▶ my ($name, $value) = $v =~ /\A\s*([^=;\s]+)=([^;]*)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ /\A\s*([^=;\s]+)=([^;]*)/ or next 88 0 88
468 # uncoverable condition right
469 88 ▶ if ($value eq '' || $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq '' or $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i) { } 3 85 88
Condition100%2/3
$value eq "" or $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
l!l&&r!l&&!r
3085
MC/DC100%1/2
$value eq "" or $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
$value eq "" $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
Truth table100%2/3
A or B
A= $value eq ""B= $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
ABresult
1X1
011
000
470 3 delete $self->{jar}{$name};
471 }
472 else {
473 85 $self->{jar}{$name} = $value;
474 }
475 }
476 615 return;
477 }
478  
479 684 ▶sub _jar_header {
Subroutine _jar_header: called CC=2 SCAR=6.9
480 684 my ($self) = @_;
481 684 my $jar = $self->{jar};
482 684 ▶ return unless %$jar;
Branch: 1 branch
BranchTrueFalseTotal
unless %$jar 566 118 684
483 118 return join '; ', map { "$_=$jar->{$_}" } sort keys %$jar;
484 }
485  
486 # ---- the response ------------------------------------------------------------
487  
488 # uncoverable branch false
489 5 ▶sub status { $_[0]{res} ? $_[0]{res}{status} : undef }
Subroutine status: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'res'} ? : 5 0 5
490 # uncoverable branch false
491 26 ▶sub body { $_[0]{res} ? $_[0]{res}{body} : undef }
Subroutine body: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'res'} ? : 26 0 26
492  
493 167 ▶sub header {
Subroutine header: called CC=4 SCAR=13.9
Pod documented
494 167 my ($self, $name) = @_;
495 # uncoverable branch true
496 167 ▶ return unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 167 167
497 167 my @h = @{ $self->{res}{headers} };
498 167 ▶ while (my ($k, $v) = splice @h, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@h, 0, 2)) 365 17 382
499 365 ▶ return $v if lc $k eq lc $name;
Branch: 1 branch
BranchTrueFalseTotal
if lc $k eq lc $name 150 215 365
500 }
501 17 return undef;
502 }
503  
504 164 ▶sub json {
Subroutine json: called CC=3 SCAR=11.0
Pod documented
505 164 my ($self) = @_;
506 # uncoverable branch true
507 164 ▶ return unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 164 164
508 164 ▶ return $self->{json} //= eval { File::Raw::JSON::file_json_decode($self->{res}{body}) };
Condition100%3/3
$self->{"json"} //= eval { do { File::Raw::JSON::file_json_decode($self->{"res"}{"body"}) } }
l!l&&r!l&&!r
511103
MC/DC100%2/2
$self->{"json"} //= eval { do { File::Raw::JSON::file_json_decode($self->{"res"}{"body"}) } }
$self->{"json"} eval { do { File::Raw::JSON::file_json_decode($self->{"res"}{"body"}) } }
Truth table100%3/3
A //= B
A= $self->{"json"}B= eval { do { File::Raw::JSON::file_json_decode($self->{"res"}{"body"}) } }
ABresult
1X1
011
000
509 }
510  
511 8 ▶sub xml {
Subroutine xml: called CC=3 SCAR=11.0
Pod documented
512 8 my ($self) = @_;
513 # uncoverable branch true
514 8 ▶ return unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 8 8
515 8 ▶ return $self->{xml} //= eval {
Condition100%3/3
$self->{"xml"} //= eval { do { File::Raw::XML::file_xml_decode($self->{"res"}{"body"}) } }
l!l&&r!l&&!r
341
MC/DC100%2/2
$self->{"xml"} //= eval { do { File::Raw::XML::file_xml_decode($self->{"res"}{"body"}) } }
$self->{"xml"} eval { do { File::Raw::XML::file_xml_decode($self->{"res"}{"body"}) } }
Truth table100%3/3
A //= B
A= $self->{"xml"}B= eval { do { File::Raw::XML::file_xml_decode($self->{"res"}{"body"}) } }
ABresult
1X1
011
000
516 5 File::Raw::XML::file_xml_decode($self->{res}{body});
517 };
518 }
519  
520 5 ▶sub cookie { $_[0]{jar}{ $_[1] } }
Subroutine cookie: called CC=1 SCAR=0.0
Pod documented
521  
522 13 ▶sub csrf_token { $_[0]{jar}{ $_[0]{csrf_cookie} } }
Subroutine csrf_token: called CC=1 SCAR=0.0
Pod documented
523  
524 3 ▶sub reset_session { %{ $_[0]{jar} } = (); $_[0] }
Subroutine reset_session: called CC=1 SCAR=0.0
Pod documented
525  
526 # ---- assertions --------------------------------------------------------------
527  
528 3 ▶sub _no_response {
Subroutine _no_response: called CC=1 SCAR=0.0
529 3 my ($self, $name) = @_;
530 3 local $Test::Builder::Level = $Test::Builder::Level + 1;
531 3 $TB->ok(0, $name);
532 3 $TB->diag('no response - did the last *_ok request fail?');
533 3 return $self;
534 }
535  
536 413 ▶sub status_is {
Subroutine status_is: called CC=4 SCAR=13.9
Pod documented
537 413 my ($self, $want, $name) = @_;
538 413 local $Test::Builder::Level = $Test::Builder::Level + 1;
539 # uncoverable condition false
540 413 ▶ $name //= "status is $want";
Condition100%2/2
$name //= "status is $want"
l!l
155258
MC/DC100%1/1
$name //= "status is $want"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
541 413 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 3 410 413
542 410 ▶ $TB->is_num($self->{res}{status}, $want, $name)
Branch: 1 branch
BranchTrueFalseTotal
$TB->is_num($self->{"res"}{"status"}, $want, $name) or $TB->diag('body: ' . $self->_body_head) 407 3 410
543 or $TB->diag('body: ' . $self->_body_head);
544 410 return $self;
545 }
546  
547 10 ▶sub status_isnt {
Subroutine status_isnt: called CC=3 SCAR=11.0
Pod documented
548 10 my ($self, $want, $name) = @_;
549 10 local $Test::Builder::Level = $Test::Builder::Level + 1;
550 # uncoverable condition false
551 10 ▶ $name //= "status is not $want";
Condition100%2/2
$name //= "status is not $want"
l!l
91
MC/DC100%1/1
$name //= "status is not $want"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
552 # uncoverable branch true
553 10 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 10 10
554 10 $TB->isnt_num($self->{res}{status}, $want, $name);
555 10 return $self;
556 }
557  
558 84 ▶sub header_is {
Subroutine header_is: called CC=4 SCAR=13.9
Pod documented
559 84 my ($self, $h, $want, $name) = @_;
560 84 local $Test::Builder::Level = $Test::Builder::Level + 1;
561 # uncoverable condition false
562 84 ▶ $name //= "$h header is " . (defined $want ? "'$want'" : 'undef');
Branch: 1 branch
BranchTrueFalseTotal
defined $want ? : 68 5 73
Condition100%2/2
$name //= "$h header is " . (defined $want ? "'${want}'" : "undef")
l!l
1173
MC/DC100%1/1
$name //= "$h header is " . (defined $want ? "'${want}'" : "undef")
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
563 # uncoverable branch true
564 84 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 84 84
565 84 $TB->is_eq($self->header($h), $want, $name);
566 84 return $self;
567 }
568  
569 10 ▶sub header_like {
Subroutine header_like: called CC=4 SCAR=13.9
Pod documented
570 10 my ($self, $h, $re, $name) = @_;
571 10 local $Test::Builder::Level = $Test::Builder::Level + 1;
572 # uncoverable condition false
573 10 ▶ $name //= "$h header matches";
Condition100%2/2
$name //= "$h header matches"
l!l
28
MC/DC100%1/1
$name //= "$h header matches"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
574 # uncoverable branch true
575 10 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 10 10
576 # uncoverable condition right
577 10 ▶ $TB->like($self->header($h) // '', $re, $name);
Condition100%1/2
$self->header($h) // ""
l!l
100
MC/DC100%0/1
$self->header($h) // ""
$self->header($h)
Truth table100%1/2
A
A= $self->header($h)
Aresult
11
00
578 10 return $self;
579 }
580  
581 1 ▶sub header_exists {
Subroutine header_exists: called CC=3 SCAR=11.0
Pod documented
582 1 my ($self, $h, $name) = @_;
583 1 local $Test::Builder::Level = $Test::Builder::Level + 1;
584 # uncoverable condition left
585 # uncoverable condition false
586 1 ▶ $name //= "$h header exists";
Condition100%1/2
$name //= "$h header exists"
l!l
01
MC/DC100%0/1
$name //= "$h header exists"
$name
Truth table100%1/2
A
A= $name
Aresult
11
00
587 # uncoverable branch true
588 1 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 1 1
589 1 $TB->ok(defined $self->header($h), $name);
590 1 return $self;
591 }
592  
593 115 ▶sub content_is {
Subroutine content_is: called CC=3 SCAR=11.0
Pod documented
594 115 my ($self, $want, $name) = @_;
595 115 local $Test::Builder::Level = $Test::Builder::Level + 1;
596 115 ▶ $name //= 'exact body';
Condition100%2/2
$name //= "exact body"
l!l
8332
MC/DC100%1/1
$name //= "exact body"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
597 # uncoverable branch true
598 115 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 115 115
599 115 $TB->is_eq($self->{res}{body}, $want, $name);
600 115 return $self;
601 }
602  
603 43 ▶sub content_like {
Subroutine content_like: called CC=3 SCAR=11.0
Pod documented
604 43 my ($self, $re, $name) = @_;
605 43 local $Test::Builder::Level = $Test::Builder::Level + 1;
606 43 ▶ $name //= 'body matches';
Condition100%2/2
$name //= "body matches"
l!l
2122
MC/DC100%1/1
$name //= "body matches"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
607 # uncoverable branch true
608 43 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 43 43
609 43 $TB->like($self->{res}{body}, $re, $name);
610 43 return $self;
611 }
612  
613 8 ▶sub content_unlike {
Subroutine content_unlike: called CC=3 SCAR=11.0
Pod documented
614 8 my ($self, $re, $name) = @_;
615 8 local $Test::Builder::Level = $Test::Builder::Level + 1;
616 8 ▶ $name //= 'body does not match';
Condition100%2/2
$name //= "body does not match"
l!l
62
MC/DC100%1/1
$name //= "body does not match"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
617 # uncoverable branch true
618 8 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 8 8
619 8 $TB->unlike($self->{res}{body}, $re, $name);
620 8 return $self;
621 }
622  
623 # RFC 6901: '' is the whole document, '/a/0/b' walks in. Returns
624 # (found, value).
625 182 ▶sub _ptr_get {
Subroutine _ptr_get: called CC=10 SCAR=23.0
626 182 my ($doc, $ptr) = @_;
627 # uncoverable condition left
628 182 ▶ return (1, $doc) if !defined $ptr || $ptr eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ptr or $ptr eq "" 2 180 182
Condition100%2/3
not defined $ptr or $ptr eq ""
l!l&&r!l&&!r
02180
MC/DC100%1/2
not defined $ptr or $ptr eq ""
not defined $ptr $ptr eq ""
Truth table100%2/3
not(A) or B
A= not defined $ptrB= $ptr eq ""
ABresult
1X1
011
000
629 # uncoverable branch true
630 180 ▶ return (0, undef) unless $ptr =~ s{\A/}{};
Branch: 1 branch
BranchTrueFalseTotal
unless $ptr =~ s[\A/][] 0 180 180
631 180 for my $tok (split m{/}, $ptr, -1) {
632 269 $tok =~ s/~1/\//g;
633 269 $tok =~ s/~0/~/g;
634 269 ▶ if (ref $doc eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $doc eq 'HASH') { } 236 33 269
elsif (ref $doc eq 'ARRAY') { } 30 3 33
635 236 ▶ return (0, undef) unless exists $doc->{$tok};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $doc->{$tok} 6 230 236
636 230 $doc = $doc->{$tok};
637 }
638 elsif (ref $doc eq 'ARRAY') {
639 # uncoverable branch true
640 # uncoverable condition left
641 # uncoverable condition right
642 30 ▶ return (0, undef) unless $tok =~ /\A\d+\z/ && $tok <= $#$doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok =~ /\A\d+\z/ and $tok <= $doc->$#* 0 30 30
Condition100%1/3
$tok =~ /\A\d+\z/ and $tok <= $doc->$#*
!ll&&!rl&&r
0030
MC/DC100%0/2
$tok =~ /\A\d+\z/ and $tok <= $doc->$#*
$tok =~ /\A\d+\z/ $tok <= $doc->$#*
Truth table100%1/3
A and B
A= $tok =~ /\A\d+\z/B= $tok <= $doc->$#*
ABresult
0X0
100
111
643 30 $doc = $doc->[$tok];
644 }
645 3 else { return (0, undef) }
646 }
647 171 return (1, $doc);
648 }
649  
650 144 ▶sub _json_at {
Subroutine _json_at: called CC=3 SCAR=11.0
651 144 my ($self, $ptr, $name) = @_;
652 144 local $Test::Builder::Level = $Test::Builder::Level + 1;
653 144 my $doc = $self->json;
654 144 ▶ unless (defined $doc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $doc) 3 141 144
655 3 $TB->ok(0, $name);
656 3 $TB->diag('the body did not decode as JSON: ' . $self->_body_head);
657 3 return;
658 }
659 141 my ($found, $got) = _ptr_get($doc, $ptr);
660 141 ▶ unless ($found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 6 135 141
661 6 $TB->ok(0, $name);
662 6 $TB->diag("nothing at JSON pointer '$ptr' in " . $self->_body_head);
663 6 return;
664 }
665 135 return \$got;
666 }
667  
668 111 ▶sub json_is {
Subroutine json_is: called CC=6 SCAR=17.9
Pod documented
669 111 my ($self, $ptr, $want, $name) = @_;
670 111 local $Test::Builder::Level = $Test::Builder::Level + 1;
671 # uncoverable condition false
672 111 ▶ $name //= "json at '$ptr'";
Condition100%2/2
$name //= "json at '${ptr}'"
l!l
6843
MC/DC100%1/1
$name //= "json at '${ptr}'"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
673 # uncoverable branch true
674 111 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 111 111
675 111 ▶ my $slot = $self->_json_at($ptr, $name) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $slot = $self->_json_at($ptr, $name) or return $self 102 9 111
676 102 my $got = $$slot;
677 # uncoverable condition right
678 102 ▶ if (ref $got || ref $want) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $got or ref $want) { } 7 95 102
Condition100%2/3
ref $got or ref $want
l!l&&r!l&&!r
7095
MC/DC100%1/2
ref $got or ref $want
ref $got ref $want
Truth table100%2/3
A or B
A= ref $gotB= ref $want
ABresult
1X1
011
000
679 # deep-compare through canonical JSON, wrapped so scalars encode
680 7 $TB->is_eq(File::Raw::JSON::file_json_encode([$got], sort_keys => 1),
681 File::Raw::JSON::file_json_encode([$want], sort_keys => 1), $name);
682 }
683 else {
684 95 $TB->is_eq($got, $want, $name);
685 }
686 102 return $self;
687 }
688  
689 6 ▶sub json_has {
Subroutine json_has: called CC=4 SCAR=14.0
Pod documented
690 6 my ($self, $ptr, $name) = @_;
691 6 local $Test::Builder::Level = $Test::Builder::Level + 1;
692 # uncoverable condition false
693 6 ▶ $name //= "json has '$ptr'";
Condition100%2/2
$name //= "json has '${ptr}'"
l!l
24
MC/DC100%1/1
$name //= "json has '${ptr}'"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
694 # uncoverable branch true
695 6 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 6 6
696 # uncoverable branch true
697 6 ▶ my $slot = $self->_json_at($ptr, $name) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $slot = $self->_json_at($ptr, $name) or return $self 6 0 6
698 6 $TB->ok(1, $name);
699 6 return $self;
700 }
701  
702 27 ▶sub json_like {
Subroutine json_like: called CC=6 SCAR=18.0
Pod documented
703 27 my ($self, $ptr, $re, $name) = @_;
704 27 local $Test::Builder::Level = $Test::Builder::Level + 1;
705 # uncoverable condition false
706 27 ▶ $name //= "json at '$ptr' matches";
Condition100%2/2
$name //= "json at '${ptr}' matches"
l!l
1512
MC/DC100%1/1
$name //= "json at '${ptr}' matches"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
707 # uncoverable branch true
708 27 ▶ return $self->_no_response($name) unless $self->{res};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"res"} 0 27 27
709 # uncoverable branch true
710 27 ▶ my $slot = $self->_json_at($ptr, $name) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $slot = $self->_json_at($ptr, $name) or return $self 27 0 27
711 # uncoverable branch false
712 # uncoverable condition left
713 # uncoverable condition right
714 27 ▶ $TB->like(defined $$slot && !ref $$slot ? $$slot : '', $re, $name);
Branch: 1 branch
BranchTrueFalseTotal
defined $$slot && !ref($$slot) ? : 27 0 27
Condition100%1/3
defined $$slot and not ref $$slot
!ll&&!rl&&r
0027
MC/DC100%0/2
defined $$slot and not ref $$slot
defined $$slot not ref $$slot
Truth table100%1/3
A and not(B)
A= defined $$slotB= not ref $$slot
ABresult
0X0
100
111
715 27 return $self;
716 }
717  
718 15 ▶sub _body_head {
Subroutine _body_head: called CC=4 SCAR=13.9
719 15 my ($self) = @_;
720 # uncoverable branch false
721 15 ▶ my $b = $self->{res} ? $self->{res}{body} : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'res'} ? : 15 0 15
722 15 ▶ $b = substr($b, 0, 500) . '...' if length $b > 500;
Branch: 1 branch
BranchTrueFalseTotal
if length $b > 500 3 12 15
723 # uncoverable branch false
724 15 ▶ return length $b ? $b : '(empty body)';
Branch: 1 branch
BranchTrueFalseTotal
length $b ? : 15 0 15
725 }
726  
727 # ---- server-sent events ------------------------------------------------------
728  
729 38 ▶sub sse_ok {
Subroutine sse_ok: called CC=11 SCAR=24.0
Pod documented
730 38 my ($self, $path, %o) = @_;
731 38 local $Test::Builder::Level = $Test::Builder::Level + 1;
732 38 $path = $self->_resolve_path($path);
733 # uncoverable condition left
734 # uncoverable condition false
735 38 ▶ my $name = $o{name} // "SSE $path";
Condition100%1/2
$o{"name"} // "SSE $path"
l!l
038
MC/DC100%0/1
$o{"name"} // "SSE $path"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
Aresult
11
00
736 # uncoverable condition left
737 38 ▶ $o{headers}{Accept} //= 'text/event-stream';
Condition100%1/2
$o{"headers"}{"Accept"} //= "text/event-stream"
l!l
038
MC/DC100%0/1
$o{"headers"}{"Accept"} //= "text/event-stream"
$o{"headers"}{"Accept"}
Truth table100%1/2
A
A= $o{"headers"}{"Accept"}
Aresult
11
00
738 38 my $env = $self->_build_env(GET => $path, %o);
739 38 $env->{'psgi.streaming'} = 1;
740 38 delete $self->{sse};
741 38 my $r = eval { $self->{app}->($env) };
742 38 my $err = $@;
743 38 ▶ if (ref $r eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $r eq "CODE") 29 9 38
744 29 $r = eval { $self->_drive_streaming($r) };
745 # uncoverable condition left
746 # uncoverable condition right
747 29 ▶ $err ||= $@;
Condition100%1/3
$err ||= $@
l!l&&r!l&&!r
0029
MC/DC100%0/2
$err ||= $@
$err $@
Truth table100%1/3
A ||= B
A= $errB= $@
ABresult
1X1
011
000
748 }
749 38 ▶ unless (ref $r eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $r eq "ARRAY") 6 32 38
750 6 $self->{res} = undef;
751 6 $TB->ok(0, $name);
752 6 ▶ $TB->diag($err ? "the application died: $err"
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 3 3 6
753 : 'no response from the sse route');
754 6 return $self;
755 }
756 32 $self->_set_response($r);
757 # uncoverable condition right
758 32 ▶ my $ct = $self->header('Content-Type') // '';
Condition100%1/2
$self->header("Content-Type") // ""
l!l
320
MC/DC100%0/1
$self->header("Content-Type") // ""
$self->header("Content-Type")
Truth table100%1/2
A
A= $self->header("Content-Type")
Aresult
11
00
759 # uncoverable condition left
760 32 ▶ if ($r->[0] == 200 && $ct =~ m{\Atext/event-stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->[0] == 200 and $ct =~ m[\Atext/event-stream]) { } 29 3 32
Condition100%2/3
$r->[0] == 200 and $ct =~ m[\Atext/event-stream]
!ll&&!rl&&r
0329
MC/DC100%1/2
$r->[0] == 200 and $ct =~ m[\Atext/event-stream]
$r->[0] == 200 $ct =~ m[\Atext/event-stream]
Truth table100%2/3
A and B
A= $r->[0] == 200B= $ct =~ m[\Atext/event-stream]
ABresult
0X0
100
111
761 29 $self->{sse} = _parse_sse($self->{res}{body});
762 29 $TB->ok(1, $name);
763 }
764 else {
765 3 $TB->ok(0, $name);
766 # uncoverable condition right
767 3 ▶ $TB->diag("expected a 200 text/event-stream, got $r->[0] "
Condition100%1/2
$ct || '(no content type)'
l!l
30
MC/DC100%0/1
$ct || '(no content type)'
$ct
Truth table100%1/2
A
A= $ct
Aresult
11
00
768 . ($ct || '(no content type)') . ': ' . $self->_body_head);
769 }
770 32 return $self;
771 }
772  
773 # The spec's dispatch loop: fields accumulate, a blank line dispatches.
774 29 ▶sub _parse_sse {
Subroutine _parse_sse: called CC=11 SCAR=24.0
775 29 my ($bytes) = @_;
776 29 my (@events, @comments, %cur);
777 29 for my $line (split /\n/, $bytes, -1) {
778 172 $line =~ s/\r\z//;
779 172 ▶ if ($line eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 79 93 172
780 79 ▶ push @events, {%cur} if %cur;
Branch: 1 branch
BranchTrueFalseTotal
if %cur 50 29 79
781 79 %cur = ();
782 79 next;
783 }
784 93 ▶ if ($line =~ /\A:\s?(.*)\z/s) { push @comments, $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A:\s?(.*)\z/s) 7 86 93
785 86 my ($field, $value) = $line =~ /\A([^:]+)(?::\s?(.*))?\z/s;
786 # uncoverable condition right
787 86 ▶ $value //= '';
Condition100%1/2
$value //= ""
l!l
860
MC/DC100%0/1
$value //= ""
$value
Truth table100%1/2
A
A= $value
Aresult
11
00
788 # uncoverable branch false count:4
789 86 ▶ if ($field eq 'data') { $cur{data} = defined $cur{data}
Branch: 4 branches
BranchTrueFalseTotal
if ($field eq 'data') { } 57 29 86
elsif ($field eq 'event') { } 16 13 29
elsif ($field eq 'id') { } 7 6 13
elsif ($field eq 'retry') { } 6 0 6
790 57 ▶ ? "$cur{data}\n$value" : $value }
Branch: 1 branch
BranchTrueFalseTotal
defined $cur{'data'} ? : 7 50 57
791 16 elsif ($field eq 'event') { $cur{event} = $value }
792 7 elsif ($field eq 'id') { $cur{id} = $value }
793 6 elsif ($field eq 'retry') { $cur{retry} = $value }
794 }
795 29 return { events => \@events, comments => \@comments };
796 }
797  
798 # uncoverable branch false
799 17 ▶sub sse_events { $_[0]{sse} ? $_[0]{sse}{events} : undef }
Subroutine sse_events: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'sse'} ? : 17 0 17
800 # uncoverable branch false
801 7 ▶sub sse_comments { $_[0]{sse} ? $_[0]{sse}{comments} : undef }
Subroutine sse_comments: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'sse'} ? : 7 0 7
802  
803 74 ▶sub _sse_event {
Subroutine _sse_event: called CC=3 SCAR=11.0
804 74 my ($self, $i, $name) = @_;
805 74 local $Test::Builder::Level = $Test::Builder::Level + 1;
806 74 ▶ unless ($self->{sse}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sse"}) 3 71 74
807 3 $TB->ok(0, $name);
808 3 $TB->diag('no SSE stream - did sse_ok pass?');
809 3 return;
810 }
811 71 my $ev = $self->{sse}{events}[$i];
812 71 ▶ unless ($ev) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ev) 3 68 71
813 3 $TB->ok(0, $name);
814 $TB->diag("no event $i - the stream held "
815 3 . scalar(@{ $self->{sse}{events} }) . ' event(s)');
816 3 return;
817 }
818 68 return $ev;
819 }
820  
821 16 ▶sub sse_event_is {
Subroutine sse_event_is: called CC=7 SCAR=19.5
Pod documented
822 16 my ($self, $i, $event, $data, $name) = @_;
823 16 local $Test::Builder::Level = $Test::Builder::Level + 1;
824 # uncoverable condition left
825 # uncoverable condition false
826 16 ▶ $name //= "event $i is $event";
Condition100%1/2
$name //= "event $i is $event"
l!l
016
MC/DC100%0/1
$name //= "event $i is $event"
$name
Truth table100%1/2
A
A= $name
Aresult
11
00
827 16 ▶ my $ev = $self->_sse_event($i, $name) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $ev = $self->_sse_event($i, $name) or return $self 10 6 16
828 # uncoverable condition right
829 10 ▶ if (($ev->{event} // '') eq $event) {
Branch: 1 branch
BranchTrueFalseTotal
if (($ev->{'event'} // '') eq $event) { } 7 3 10
Condition100%1/2
$ev->{"event"} // ""
l!l
100
MC/DC100%0/1
$ev->{"event"} // ""
$ev->{"event"}
Truth table100%1/2
A
A= $ev->{"event"}
Aresult
11
00
830 # uncoverable condition right
831 7 ▶ $TB->is_eq($ev->{data} // '', $data, $name);
Condition100%1/2
$ev->{"data"} // ""
l!l
70
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
Aresult
11
00
832 }
833 else {
834 3 $TB->ok(0, $name);
835 # uncoverable condition right
836 3 ▶ $TB->diag("event $i is named '" . ($ev->{event} // '')
Condition100%1/2
$ev->{"event"} // ""
l!l
30
MC/DC100%0/1
$ev->{"event"} // ""
$ev->{"event"}
Truth table100%1/2
A
A= $ev->{"event"}
Aresult
11
00
837 . "', not '$event'");
838 }
839 10 return $self;
840 }
841  
842 14 ▶sub sse_data_is {
Subroutine sse_data_is: called CC=4 SCAR=14.0
Pod documented
843 14 my ($self, $i, $data, $name) = @_;
844 14 local $Test::Builder::Level = $Test::Builder::Level + 1;
845 # uncoverable condition false
846 14 ▶ $name //= "event $i data";
Condition100%2/2
$name //= "event $i data"
l!l
77
MC/DC100%1/1
$name //= "event $i data"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
847 # uncoverable branch true
848 14 ▶ my $ev = $self->_sse_event($i, $name) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $ev = $self->_sse_event($i, $name) or return $self 14 0 14
849 # uncoverable condition right
850 14 ▶ $TB->is_eq($ev->{data} // '', $data, $name);
Condition100%1/2
$ev->{"data"} // ""
l!l
140
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
Aresult
11
00
851 14 return $self;
852 }
853  
854 44 ▶sub sse_json_is {
Subroutine sse_json_is: called CC=9 SCAR=22.0
Pod documented
855 44 my ($self, $i, $ptr, $want, $name) = @_;
856 44 local $Test::Builder::Level = $Test::Builder::Level + 1;
857 # uncoverable condition false
858 44 ▶ $name //= "event $i json at '$ptr'";
Condition100%2/2
$name //= "event $i json at '${ptr}'"
l!l
2123
MC/DC100%1/1
$name //= "event $i json at '${ptr}'"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
859 # uncoverable branch true
860 44 ▶ my $ev = $self->_sse_event($i, $name) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $ev = $self->_sse_event($i, $name) or return $self 44 0 44
861 # uncoverable condition right
862 44 ▶ my $doc = eval { File::Raw::JSON::file_json_decode($ev->{data} // '') };
Condition100%1/2
$ev->{"data"} // ""
l!l
440
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
Aresult
11
00
863 44 ▶ unless (defined $doc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $doc) 3 41 44
864 3 $TB->ok(0, $name);
865 # uncoverable condition right
866 3 ▶ $TB->diag("event $i data is not JSON: " . ($ev->{data} // ''));
Condition100%1/2
$ev->{"data"} // ""
l!l
30
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
Aresult
11
00
867 3 return $self;
868 }
869 41 my ($found, $got) = _ptr_get($doc, $ptr);
870 41 ▶ unless ($found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 3 38 41
871 3 $TB->ok(0, $name);
872 3 $TB->diag("nothing at JSON pointer '$ptr' in event $i");
873 3 return $self;
874 }
875 # uncoverable condition right
876 38 ▶ if (ref $got || ref $want) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $got or ref $want) { } 14 24 38
Condition100%2/3
ref $got or ref $want
l!l&&r!l&&!r
14024
MC/DC100%1/2
ref $got or ref $want
ref $got ref $want
Truth table100%2/3
A or B
A= ref $gotB= ref $want
ABresult
1X1
011
000
877 14 $TB->is_eq(File::Raw::JSON::file_json_encode([$got], sort_keys => 1),
878 File::Raw::JSON::file_json_encode([$want], sort_keys => 1), $name);
879 }
880 else {
881 24 $TB->is_eq($got, $want, $name);
882 }
883 38 return $self;
884 }
885  
886 # ---- websockets --------------------------------------------------------------
887  
888 # Whether the live (forked Hyperman) transport can run here at all - tests
889 # use this to SKIP, the same way t/1011-ws-live.t does.
890 9 ▶sub ws_live_available {
Subroutine ws_live_available: called CC=2 SCAR=6.9
Pod documented
891 # uncoverable branch false
892 9 ▶ return eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Hyperman; require Punk::WebSocket; Punk::WebSocket::_hm_available() } } ? : 9 0 9
893 9 require Hyperman;
894 9 require Punk::WebSocket;
895 9 Punk::WebSocket::_hm_available();
896 } ? 1 : 0;
897 }
898  
899 57 ▶sub websocket_ok {
Subroutine websocket_ok: called CC=14 SCAR=26.4
Pod documented
900 57 my ($self, $path, %o) = @_;
901 57 local $Test::Builder::Level = $Test::Builder::Level + 1;
902 57 $path = $self->_resolve_path($path);
903 # uncoverable condition left
904 # uncoverable condition false
905 57 ▶ my $name = $o{name} // "websocket $path";
Condition100%1/2
$o{"name"} // "websocket $path"
l!l
057
MC/DC100%0/1
$o{"name"} // "websocket $path"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
Aresult
11
00
906 57 $self->_ws_teardown;
907  
908 57 ▶ if (!$o{live}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o{"live"}) 55 2 57
909 55 my ($conn, $hdr, $key, $status) = $self->_ws_inprocess($path, %o);
910 43 ▶ if ($status == 101) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 101) 35 8 43
911 35 my ($acc) = $hdr =~ /Sec-WebSocket-Accept: (\S+)/i;
912 35 $self->{ws} = $conn;
913 35 $self->{ws_hdr} = $hdr;
914 # uncoverable condition right
915 35 ▶ $TB->is_eq($acc // '', Punk::Test::WS::accept_key($key), $name);
Condition100%1/2
$acc // ""
l!l
350
MC/DC100%0/1
$acc // ""
$acc
Truth table100%1/2
A
A= $acc
Aresult
11
00
916 35 return $self;
917 }
918 # uncoverable branch false
919 8 ▶ $conn->close if $conn;
Branch: 1 branch
BranchTrueFalseTotal
if $conn 8 0 8
920 8 ▶ if ($status != 501) { # 501 = this transport cannot upgrade; go live
Branch: 1 branch
BranchTrueFalseTotal
if ($status != 501) 6 2 8
921 6 $TB->ok(0, $name);
922 # uncoverable branch false
923 6 ▶ $TB->diag($status
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 6 0 6
924 ? "the upgrade was answered with a $status:\n$hdr"
925 : 'no bytes came back from the upgrade request');
926 6 return $self;
927 }
928 }
929  
930 # uncoverable branch true
931 4 ▶ unless (ws_live_available()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ws_live_available()) 0 4 4
932 # uncoverable statement
933 0 $TB->ok(0, $name);
934 # uncoverable statement
935 0 $TB->diag('this route needs the live transport (Hyperman 0.11+); '
936 . 'guard the test with Punk::Test::ws_live_available');
937 # uncoverable statement
938 0 return $self;
939 }
940 4 my ($conn, $hdr, $key) = $self->_ws_live($path, %o);
941 # uncoverable branch true
942 2 ▶ unless ($conn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn) 0 2 2
943 # uncoverable statement
944 0 $TB->ok(0, $name);
945 # uncoverable statement
946 # uncoverable condition left
947 # uncoverable condition right
948 0 ▶ $TB->diag($hdr // 'could not connect to the live worker');
Condition100%0/2
$hdr // "could not connect to the live worker"
l!l
00
MC/DC100%0/1
$hdr // "could not connect to the live worker"
$hdr
Truth table100%0/2
A
A= $hdr
Aresult
11
00
949 # uncoverable statement
950 0 return $self;
951 }
952 2 ▶ if ($hdr =~ m{\AHTTP/1\.1 101 }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr =~ m[\AHTTP/1\.1 101 ]) { } 1 1 2
953 1 my ($acc) = $hdr =~ /Sec-WebSocket-Accept: (\S+)/i;
954 1 $self->{ws} = $conn;
955 1 $self->{ws_hdr} = $hdr;
956 # uncoverable condition right
957 1 ▶ $TB->is_eq($acc // '', Punk::Test::WS::accept_key($key), $name);
Condition100%1/2
$acc // ""
l!l
10
MC/DC100%0/1
$acc // ""
$acc
Truth table100%1/2
A
A= $acc
Aresult
11
00
958 }
959 else {
960 1 $conn->close;
961 1 $TB->ok(0, $name);
962 1 my ($line) = split /\r\n/, $hdr;
963 # uncoverable condition right
964 1 ▶ $TB->diag('the upgrade was answered with: ' . ($line // '(nothing)'));
Condition100%1/2
$line // "(nothing)"
l!l
10
MC/DC100%0/1
$line // "(nothing)"
$line
Truth table100%1/2
A
A= $line
Aresult
11
00
965 }
966 2 return $self;
967 }
968  
969 # In-process transport: the app runs in a fork with one end of a socketpair
970 # as psgix.io - so a blocking => 1 route streams to us in real time while
971 # this side sends and asserts interactively. The child answers non-upgrade
972 # triplets (a guard's 403, the 501 of a route this transport cannot carry)
973 # as minimal HTTP so the parent can see why.
974 55 ▶sub _ws_inprocess {
Subroutine _ws_inprocess: called CC=13 SCAR=25.7
975 55 my ($self, $path, %o) = @_;
976 my ($env, $key) = Punk::Test::WS::upgrade_env(
977 55 path => $path, query => $o{query}, protocol => $o{protocol});
978 55 ▶ if (my $h = $o{headers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = $o{"headers"}) 10 45 55
979 10 for my $k (keys %$h) {
980 10 my $ek = uc $k; $ek =~ tr/-/_/;
981 10 $env->{"HTTP_$ek"} = $h->{$k};
982 }
983 }
984 55 ▶ if (my $jar = $self->_jar_header) { $env->{HTTP_COOKIE} = $jar }
Branch: 1 branch
BranchTrueFalseTotal
if (my $jar = $self->_jar_header) 15 40 55
985  
986 # uncoverable branch true
987 55 ▶ socketpair(my $ours, my $theirs, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
Branch: 1 branch
BranchTrueFalseTotal
socketpair my $ours, my $theirs, 1, 1, 0 or die "Punk::Test: socketpair: $!" 55 0 55
988 or die "Punk::Test: socketpair: $!";
989 # uncoverable condition right
990 55 ▶ my $pid = fork // die "Punk::Test: fork: $!";
Condition100%1/2
fork // die("Punk::Test: fork: $!")
l!l
550
MC/DC100%0/1
fork // die("Punk::Test: fork: $!")
fork
Truth table100%1/2
A
A= fork
Aresult
11
00
991 55 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 12 43 55
992 # the child owns no test state: keep it off the TAP pipe entirely,
993 # and leave by exit with the test ending turned off, so the counters flush
994 12 close $ours;
995 12 open STDIN, '<', '/dev/null';
996 12 open STDOUT, '>', '/dev/null';
997 12 open STDERR, '>', '/dev/null';
998 12 $env->{'psgix.io'} = $theirs;
999 12 my $r = eval { $self->{app}->($env) };
1000 # uncoverable branch false count:2
1001 12 ▶ if (ref $r eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $r eq 'ARRAY') { } 11 1 12
elsif (not defined $r) { } 1 0 1
1002 # a successful blocking upgrade already spoke on the socket and
1003 # returns the empty 200 sentinel; anything else (a guard's 403,
1004 # the 501 of a route this transport cannot carry, a plain route
1005 # answering) is relayed as minimal HTTP so the parent sees why
1006 my $body = ref $r->[2] eq 'ARRAY'
1007 # uncoverable branch false
1008 11 ▶ ? join('', grep { defined } @{ $r->[2] }) : '';
Branch: 1 branch
BranchTrueFalseTotal
ref $r->[2] eq 'ARRAY' ? : 11 0 11
1009 # uncoverable condition right
1010 11 ▶ syswrite $theirs, "HTTP/1.1 $r->[0] X\r\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $r->[0] == 200 and not length $body 2 9 11
Condition100%2/3
$r->[0] == 200 and not length $body
!ll&&!rl&&r
209
MC/DC100%1/2
$r->[0] == 200 and not length $body
$r->[0] == 200 not length $body
Truth table100%2/3
A and not(B)
A= $r->[0] == 200B= not length $body
ABresult
0X0
100
111
1011 . "Content-Length: " . length($body) . "\r\n"
1012 . "\r\n$body"
1013 unless $r->[0] == 200 && !length $body;
1014 }
1015 elsif (!defined $r) {
1016 1 syswrite $theirs, "HTTP/1.1 500 X\r\n\r\n";
1017 }
1018 12 Test::Builder->new->no_ending(1);
1019 12 exit 0;
1020 }
1021 43 close $theirs;
1022 my $conn = Punk::Test::WS::Conn->new(
1023 43 sock => $ours, timeout => $self->{timeout}, pid => $pid);
1024 43 my $hdr = $conn->read_headers;
1025 43 my ($status) = $hdr =~ m{\AHTTP/1\.1 (\d+)};
1026 # uncoverable condition right
1027 43 ▶ return ($conn, $hdr, $key, $status // 0);
Condition100%1/2
$status // 0
l!l
430
MC/DC100%0/1
$status // 0
$status
Truth table100%1/2
A
A= $status
Aresult
11
00
1028 }
1029  
1030 # Live transport: one forked Hyperman worker per client, started on first
1031 # use, speaking real TCP - fully interactive, and the same machinery as
1032 # t/1011-ws-live.t.
1033 4 ▶sub _ws_live {
Subroutine _ws_live: called CC=5 SCAR=16.3
1034 4 my ($self, $path, %o) = @_;
1035 # uncoverable branch true
1036 4 ▶ my $host = $self->_live_host or return (undef, 'live worker failed to start');
Branch: 1 branch
BranchTrueFalseTotal
my $host = $self->_live_host or return undef, "live worker failed to start" 2 0 2
1037 2 require IO::Socket::INET;
1038 # uncoverable branch true
1039 2 ▶ my $sock = IO::Socket::INET->new(PeerAddr => $host)
Branch: 1 branch
BranchTrueFalseTotal
my $sock = "IO::Socket::INET"->new("PeerAddr", $host) or return undef, "connect ${host}: $!" 2 0 2
1040 or return (undef, "connect $host: $!");
1041 2 $sock->autoflush(1);
1042 1 my @extra = map { my $k = $_; "$k: $o{headers}{$k}" }
1043 2 ▶ keys %{ $o{headers} || {} };
Condition100%2/2
$o{'headers'} || {}
l!l
11
MC/DC100%1/1
$o{'headers'} || {}
$o{'headers'}
Truth table100%2/2
A
A= $o{'headers'}
Aresult
11
00
1044 2 ▶ if (my $jar = $self->_jar_header) { push @extra, "Cookie: $jar" }
Branch: 1 branch
BranchTrueFalseTotal
if (my $jar = $self->_jar_header) 1 1 2
1045 my ($req, $key) = Punk::Test::WS::handshake_request(
1046 host => $host, path => $path, protocol => $o{protocol},
1047 2 extra => \@extra);
1048 2 syswrite $sock, $req;
1049 my $conn = Punk::Test::WS::Conn->new(
1050 2 sock => $sock, timeout => $self->{timeout});
1051 2 my $hdr = $conn->read_headers;
1052 2 return ($conn, $hdr, $key);
1053 }
1054  
1055 4 ▶sub _live_host {
Subroutine _live_host: called CC=6 SCAR=17.9
1056 4 my ($self) = @_;
1057 # uncoverable branch true
1058 4 ▶ return $self->{live}{host} if $self->{live};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"live"} 0 4 4
1059 4 require IO::Socket::INET;
1060 4 my $port = 27000 + ($$ % 400);
1061 # uncoverable condition right
1062 4 ▶ my $pid = fork // die "Punk::Test: fork: $!";
Condition100%1/2
fork // die("Punk::Test: fork: $!")
l!l
40
MC/DC100%0/1
fork // die("Punk::Test: fork: $!")
fork
Truth table100%1/2
A
A= fork
Aresult
11
00
1063 4 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 2 2 4
1064 2 open STDIN, '<', '/dev/null';
1065 2 open STDOUT, '>', '/dev/null';
1066 2 open STDERR, '>', '/dev/null';
1067 2 eval {
1068 2 Hyperman->run(app => $self->{app}, host => '127.0.0.1',
1069 port => $port, workers => 1);
1070 };
1071 2 Test::Builder->new->no_ending(1);
1072 2 exit 0;
1073 }
1074 2 my $host = "127.0.0.1:$port";
1075 2 for (1 .. 100) {
1076 4 my $s = IO::Socket::INET->new(PeerAddr => $host);
1077 4 ▶ if ($s) { close $s; $self->{live} = { pid => $pid, host => $host };
Branch: 1 branch
BranchTrueFalseTotal
if ($s) 2 2 4
1078 2 return $host }
1079 2 select undef, undef, undef, 0.1;
1080 }
1081 # uncoverable statement
1082 0 kill 'KILL', $pid;
1083 # uncoverable statement
1084 0 waitpid $pid, 0;
1085 # uncoverable statement
1086 0 return;
1087 }
1088  
1089 40 ▶sub send_ok {
Subroutine send_ok: called CC=5 SCAR=16.1
Pod documented
1090 40 my ($self, $payload, %o) = @_;
1091 40 local $Test::Builder::Level = $Test::Builder::Level + 1;
1092 # uncoverable condition left
1093 40 ▶ my $name = $o{name} // 'send';
Condition100%1/2
$o{"name"} // "send"
l!l
040
MC/DC100%0/1
$o{"name"} // "send"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
Aresult
11
00
1094 40 ▶ unless ($self->{ws}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ws"}) 3 37 40
1095 3 $TB->ok(0, $name);
1096 3 $TB->diag('no websocket - did websocket_ok pass?');
1097 3 return $self;
1098 }
1099 my $n = $self->{ws}->send_frame(
1100 # uncoverable condition left
1101 37 ▶ opcode => $o{binary} ? 2 : ($o{opcode} // 1),
Branch: 1 branch
BranchTrueFalseTotal
$o{'binary'} ? : 6 31 37
Condition100%1/2
$o{"opcode"} // 1
l!l
031
MC/DC100%0/1
$o{"opcode"} // 1
$o{"opcode"}
Truth table100%1/2
A
A= $o{"opcode"}
Aresult
11
00
1102 payload => $payload);
1103 37 $TB->ok(defined $n, $name);
1104 37 return $self;
1105 }
1106  
1107 # The next data frame's payload, reassembling fragments, skipping pongs.
1108 48 ▶sub _next_message {
Subroutine _next_message: called CC=5 SCAR=16.1
1109 48 my ($self) = @_;
1110 48 my $payload = '';
1111 48 while (1) {
1112 48 ▶ my $f = $self->{ws}->read_frame or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $f = $self->{"ws"}->read_frame or return undef 45 3 48
1113 # uncoverable branch true
1114 45 ▶ next if $f->{opcode} == 10; # a pong
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"opcode"} == 10 0 45 45
1115 45 ▶ return { close => 1, frame => $f } if $f->{opcode} == 8;
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"opcode"} == 8 8 37 45
1116 37 $payload .= $f->{payload};
1117 # uncoverable branch false
1118 37 ▶ return { payload => $payload, frame => $f } if $f->{fin};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"fin"} 37 0 37
1119 }
1120 }
1121  
1122 42 ▶sub message_is {
Subroutine message_is: called CC=5 SCAR=16.1
Pod documented
1123 42 my ($self, $want, $name) = @_;
1124 42 local $Test::Builder::Level = $Test::Builder::Level + 1;
1125 42 ▶ $name //= 'message';
Condition100%2/2
$name //= "message"
l!l
366
MC/DC100%1/1
$name //= "message"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
1126 42 ▶ unless ($self->{ws}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ws"}) 3 39 42
1127 3 $TB->ok(0, $name);
1128 3 $TB->diag('no websocket - did websocket_ok pass?');
1129 3 return $self;
1130 }
1131 39 my $m = $self->_next_message;
1132 39 ▶ if (!$m) { $TB->ok(0, $name); $TB->diag('no frame arrived (timeout or EOF)') }
Branch: 2 branches
BranchTrueFalseTotal
if (not $m) { } 1 38 39
elsif ($m->{'close'}) { } 5 33 38
1133 5 elsif ($m->{close}) { $TB->ok(0, $name); $TB->diag('the server closed instead') }
1134 33 else { $TB->is_eq($m->{payload}, $want, $name) }
1135 39 return $self;
1136 }
1137  
1138 12 ▶sub message_like {
Subroutine message_like: called CC=5 SCAR=16.1
Pod documented
1139 12 my ($self, $re, $name) = @_;
1140 12 local $Test::Builder::Level = $Test::Builder::Level + 1;
1141 12 ▶ $name //= 'message matches';
Condition100%2/2
$name //= "message matches"
l!l
48
MC/DC100%1/1
$name //= "message matches"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
1142 12 ▶ unless ($self->{ws}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ws"}) 3 9 12
1143 3 $TB->ok(0, $name);
1144 3 $TB->diag('no websocket - did websocket_ok pass?');
1145 3 return $self;
1146 }
1147 9 my $m = $self->_next_message;
1148 9 ▶ if (!$m) { $TB->ok(0, $name); $TB->diag('no frame arrived (timeout or EOF)') }
Branch: 2 branches
BranchTrueFalseTotal
if (not $m) { } 2 7 9
elsif ($m->{'close'}) { } 3 4 7
1149 3 elsif ($m->{close}) { $TB->ok(0, $name); $TB->diag('the server closed instead') }
1150 4 else { $TB->like($m->{payload}, $re, $name) }
1151 9 return $self;
1152 }
1153  
1154 28 ▶sub finish_ok {
Subroutine finish_ok: called CC=6 SCAR=17.9
Pod documented
1155 28 my ($self, $name) = @_;
1156 28 local $Test::Builder::Level = $Test::Builder::Level + 1;
1157 # uncoverable condition left
1158 28 ▶ $name //= 'clean close';
Condition100%1/2
$name //= "clean close"
l!l
028
MC/DC100%0/1
$name //= "clean close"
$name
Truth table100%1/2
A
A= $name
Aresult
11
00
1159 28 ▶ unless ($self->{ws}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ws"}) 3 25 28
1160 3 $TB->ok(0, $name);
1161 3 $TB->diag('no websocket - did websocket_ok pass?');
1162 3 return $self;
1163 }
1164 25 $self->{ws}->send_frame(opcode => 8, payload => pack('n', 1000));
1165 25 my $echoed = 0;
1166 25 ▶ while (my $f = $self->{ws}->read_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = $self->{"ws"}->read_frame) 25 0 25
1167 # uncoverable branch false
1168 25 ▶ if ($f->{opcode} == 8) { $echoed = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"opcode"} == 8) 25 0 25
1169 }
1170 25 $TB->ok($echoed, $name);
1171 # uncoverable branch true
1172 25 ▶ $TB->diag('the close was never echoed') unless $echoed;
Branch: 1 branch
BranchTrueFalseTotal
unless $echoed 0 25 25
1173 25 $self->_ws_teardown;
1174 25 return $self;
1175 }
1176  
1177 258 ▶sub _ws_teardown {
Subroutine _ws_teardown: called CC=2 SCAR=6.9
1178 258 my ($self) = @_;
1179 258 ▶ if (my $ws = delete $self->{ws}) { $ws->close }
Branch: 1 branch
BranchTrueFalseTotal
if (my $ws = delete $self->{"ws"}) 36 222 258
1180 258 delete $self->{ws_hdr};
1181 258 return;
1182 }
1183  
1184 176 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
1185 176 my ($self) = @_;
1186 176 $self->_ws_teardown;
1187 176 ▶ if (my $live = delete $self->{live}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $live = delete $self->{"live"}) 2 174 176
1188 2 kill 'TERM', $live->{pid};
1189 2 waitpid $live->{pid}, 0;
1190 }
1191 176 return;
1192 }
1193  
1194 # psgi.input for a multipart request: a real PerlIO handle - the parser
1195 # reads it with PerlIO_read, which a tied handle never sees - whose FILL
1196 # drains the item list built by _multipart_input. @QUEUE hands the list
1197 # to PUSHED, because open() gives a via layer no arguments of ours.
1198 package
1199 Punk::Test::_MPInput;
1200  
1201 56 our @QUEUE;
1202 18 ▶sub PUSHED { bless { items => shift @QUEUE }, $_[0] }
Subroutine PUSHED: called CC=1 SCAR=0.0
1203 105 ▶sub FILL {
Subroutine FILL: called CC=5 SCAR=16.1
1204 105 my ($self) = @_;
1205 105 my $items = $self->{items};
1206 105 ▶ while (@$items) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$items) 112 0 112
1207 112 my $it = $items->[0];
1208 112 ▶ unless (ref $it) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $it) 105 7 112
1209 105 shift @$items;
1210 105 ▶ return $it if length $it;
Branch: 1 branch
BranchTrueFalseTotal
if length $it 100 5 105
1211 5 next;
1212 }
1213 7 my $n = read $it->{fh}, my $chunk, 65536;
1214 7 ▶ return $chunk if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 5 2 7
1215 2 close $it->{fh};
1216 2 shift @$items;
1217 }
1218 # uncoverable statement
1219 0 return undef;
1220 }
1221  
1222 # The psgi.streaming writer handed to a delayed response.
1223 package
1224 Punk::Test::_Writer;
1225 49 ▶sub new { bless { w => $_[1], c => $_[2] }, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
1226 103 ▶sub write { $_[0]{w}->($_[1]) }
Subroutine write: called CC=1 SCAR=0.0
1227 42 ▶sub close { ${ $_[0]{c} } = 1 }
Subroutine close: called CC=1 SCAR=0.0
1228  
1229 package Punk::Test;
1230  
1231 56 1;
1232  
1233 __END__
« blib/lib/Punk/Test/WS.pm ↑ Summary blib/lib/Punk/Plugin/I18n.pm »