| 1 | package Punk::DevError; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | our $VERSION = '0.70'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # Development error pages. Loaded only when the application compiles in the | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # development environment (Punk::App::compile_extras) - an opt-in: punk dev, | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # or PUNK_ENV=development, or the config env. Production (the default) never | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # requires this file and keeps the C dispatcher's fixed 500 byte-identical. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # The whole feature lives on the cold path: a middleware that records the | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # stack at throw time (the C dispatcher catches dies under G_EVAL, so the | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # frames must be captured where the die happens), and an on_error that | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # renders them - HTML for a browser, the production JSON shape plus a | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # trace for anything else. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # What the last die inside the middleware's scope looked like: message and | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # frames. Compared against the error that reaches on_error before use, so | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # an unrelated inner eval's die cannot decorate someone else's page. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | our $CAUGHT; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $MAX_FRAMES = 40; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | my $SNIP_BEFORE = 4; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | my $SNIP_AFTER = 4; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | sub _install { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 10 | my $user = $app->{on_error}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | my $resolved = (defined $user && (ref $user || length $user)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%3/6
defined $user and ref $user || length $user
ref $user or length $user
MC/DC100%1/3
defined $user and ref $user || length $user
defined $user
ref $user
length $user
Truth table75%2/4
A and B or C
A= defined $userB= ref $userC= length $user
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | ? $app->_resolve_target($user, 'on_error') : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | ▶ | $app->on_error(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | my ($c, $err) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | if ($resolved) { # the user's handler keeps priority | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my $r = eval { $resolved->($c, $err) }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | return $r if ref $r; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | return render($c, $err); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | }); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | $app->middleware(\&_trace_mw); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | # Wrap the PSGI app so a die anywhere under it records its frames. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | sub _trace_mw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trace_mw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | my ($inner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 41 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 41 | my ($env) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 41 | local $CAUGHT = undef; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | local $SIG{__DIE__} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | my ($e) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | my (@frames, $i); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | ▶ | for ($i = 0; my @f = caller $i; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 63 | ▶ | last if @frames >= $MAX_FRAMES; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 63 | ▶ | next if $f[0] eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | my @up = caller $i + 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 44 | ▶ | push @frames, { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | pkg => $f[0], file => $f[1], line => $f[2], | ||||||||||||||||||||||||||||||||||||||||||
| 62 | sub => @up ? $up[3] : '(main)', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | $CAUGHT = { msg => "$e", frames => \@frames }; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | die @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 41 | }; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | return $inner->($env); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # on_error's fallback in development: the debug response, flowing out | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # through punk_handle_error's ordinary coercion. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | my ($c, $err) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | my $msg = "$err"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | my $frames = ($CAUGHT && $CAUGHT->{msg} eq $msg) ? $CAUGHT->{frames} : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
$Punk::DevError::CAUGHT and $Punk::DevError::CAUGHT->{"msg"} eq $msg
MC/DC100%0/2
$Punk::DevError::CAUGHT and $Punk::DevError::CAUGHT->{"msg"} eq $msg
$Punk::DevError::CAUGHT
$Punk::DevError::CAUGHT->{"msg"} eq $msg
Truth table100%1/3
A and B
A= $Punk::DevError::CAUGHTB= $Punk::DevError::CAUGHT->{"msg"} eq $msg
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | my $accept = eval { $c->req->header('accept') } // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
eval {
do {
$c->req->header("accept")
}
} // ""
MC/DC100%1/1
eval {
do {
$c->req->header("accept")
}
} // ""
eval {
do {
$c->req->header("accept")
}
}
Truth table100%2/2
A
A= eval {
do {
$c->req->header("accept")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | ▶ | my $ctype = eval { $c->req->header('content-type') } // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
eval {
do {
$c->req->header("content-type")
}
} // ""
MC/DC100%0/1
eval {
do {
$c->req->header("content-type")
}
} // ""
eval {
do {
$c->req->header("content-type")
}
}
Truth table100%1/2
A
A= eval {
do {
$c->req->header("content-type")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | if ($accept =~ m{text/html}i && $ctype !~ /json/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
$accept =~ m[text/html]i and not $ctype =~ /json/i
MC/DC100%1/2
$accept =~ m[text/html]i and not $ctype =~ /json/i
$accept =~ m[text/html]i
not $ctype =~ /json/i
Truth table100%2/3
A and not(B)
A= $accept =~ m[text/html]iB= not $ctype =~ /json/i
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | return $c->html(_page($c, $msg, $frames), 500); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | return $c->json({ errors => [ { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | message => $msg, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | trace => [ map { "$_->{file}:$_->{line} in $_->{sub}" } @$frames ], | |||||||||||||||||||||||||||||||||||||||||
| 91 | } ] }, 500); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | # ---- the page ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 64 | ▶ | sub _e { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_e: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 64 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 64 | ▶ | $s = '' unless defined $s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 64 | $s =~ s/&/&/g; $s =~ s/</</g; $s =~ s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 64 | $s =~ s/"/"/g; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 64 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | my $REDACT = qr/pass|secret|token/i; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # Plumbing a page reader almost never wants leading the stack: the | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # framework's own dispatch, the PSGI middleware between it and the server, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # the server, and the test client. The application's frames come first with | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # snippets; these collapse into a summary list. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 10 | ▶ | sub _is_plumbing { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_plumbing: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | my ($f) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 10 | ▶ | return 1 if ($f->{pkg} // '') =~ /\A(?:Punk|Plack|Hyperman|HTTP)(?:::|\z)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/2
$f->{"pkg"} // ""
MC/DC100%0/1
$f->{"pkg"} // ""
$f->{"pkg"}
Truth table100%1/2
A
A= $f->{"pkg"}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | ▶ | return 1 if ($f->{sub} // '') =~ /\A(?:Punk|Plack|Hyperman|HTTP)::/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/2
$f->{"sub"} // ""
MC/DC100%0/1
$f->{"sub"} // ""
$f->{"sub"}
Truth table100%1/2
A
A= $f->{"sub"}
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | return 1 if ($f->{file} // '') =~ m{[/\\](?:Plack|Hyperman)[/\\]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/2
$f->{"file"} // ""
MC/DC100%0/1
$f->{"file"} // ""
$f->{"file"}
Truth table100%1/2
A
A= $f->{"file"}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # The raw query string re-assembled with matching names' values redacted - | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # it is shown verbatim in the page header otherwise, which would bypass | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # the parameter table's redaction. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | sub _redacted_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_redacted_query: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | my ($q) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | return '' unless defined $q && length $q; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
defined $q and length $q
MC/DC100%1/2
defined $q and length $q
defined $q
length $q
Truth table100%2/3
A and B
A= defined $qB= length $q
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | return join '&', map { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my ($k, $v) = split /=/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 133 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | defined $v && $k =~ $REDACT ? "$k=[redacted]" : $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
defined $v and $k =~ /$REDACT/
MC/DC100%1/2
defined $v and $k =~ /$REDACT/
defined $v
$k =~ /$REDACT/
Truth table100%2/3
A and B
A= defined $vB= $k =~ /$REDACT/
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | } split /&/, $q; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | ▶ | sub _rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rows: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | my ($h, $redact_all) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | for my $k (sort keys %$h) { | |||||||||||||||||||||||||||||||||||||||||
| 142 | 17 | my $v = $h->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 17 | ▶ | $v = defined $v ? "$v" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 17 | ▶ | $v = '[redacted]' if $redact_all->($k); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 17 | ▶ | $v = substr($v, 0, 2048) . '...' if length $v > 2048; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | $out .= '<tr><th>' . _e($k) . '</th><td>' . _e($v) . "</td></tr>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | sub _snippet { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_snippet: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | my ($file, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # uncoverable condition left count:1 | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # uncoverable condition right count:1 | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # uncoverable condition left count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # uncoverable condition right count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | return '' if !defined $file || $file =~ /\(eval/ || !-r $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/6
not defined $file or $file =~ /\(eval/ or not -r $file
not defined $file or $file =~ /\(eval/
MC/DC100%0/3
not defined $file or $file =~ /\(eval/ or not -r $file
not defined $file
$file =~ /\(eval/
not -r $file
Truth table100%1/4
not(A) or B or not(C)
A= not defined $fileB= $file =~ /\(eval/C= not -r $file
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | open my $fh, '<', $file or return ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | my @lines = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 165 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | my $from = $line - $SNIP_BEFORE; $from = 1 if $from < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | ▶ | my $to = $line + $SNIP_AFTER; $to = @lines if $to > @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | my $has_eshu = eval { require Eshu; Eshu->can('highlight_string') }; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | my $out = qq{<pre class="snippet">}; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | for my $n ($from .. $to) { | |||||||||||||||||||||||||||||||||||||||||
| 172 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 36 | ▶ | my $src = $lines[$n - 1] // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$lines[$n - 1] // ""
MC/DC100%0/1
$lines[$n - 1] // ""
$lines[$n - 1]
Truth table100%1/2
A
A= $lines[$n - 1]
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 36 | chomp $src; | |||||||||||||||||||||||||||||||||||||||||
| 175 | my $code = $has_eshu | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 36 | ▶ | ? (eval { Eshu->highlight_string($src, lang => 'perl') } // _e($src)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
eval {
do {
"Eshu"->highlight_string($src, "lang", "perl")
}
} // _e($src)
MC/DC100%0/2
eval {
do {
"Eshu"->highlight_string($src, "lang", "perl")
}
} // _e($src)
eval {
do {
"Eshu"->highlight_string($src, "lang", "perl")
}
}
_e($src)
Truth table100%1/3
A // B
A= eval {
do {
"Eshu"->highlight_string($src, "lang", "perl")
}
}B= _e($src)
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | : _e($src); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 36 | $code =~ s/\n\z//; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 36 | ▶ | my $cls = $n == $line ? 'ln hit' : 'ln'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 36 | $out .= sprintf qq{<span class="%s"><i>%4d</i> %s\n</span>}, | |||||||||||||||||||||||||||||||||||||||||
| 184 | $cls, $n, $code; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | return $out . '</pre>'; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | sub _page { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_page: called CC=24 SCAR=31.8
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my ($c, $msg, $frames) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | ▶ | my $env = eval { $c->env } || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
eval {
do {
$c->env
}
} || {}
MC/DC100%0/1
eval {
do {
$c->env
}
} || {}
eval {
do {
$c->env
}
}
Truth table100%1/2
A
A= eval {
do {
$c->env
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | my $method = $env->{REQUEST_METHOD} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$env->{"REQUEST_METHOD"} // ""
MC/DC100%0/1
$env->{"REQUEST_METHOD"} // ""
$env->{"REQUEST_METHOD"}
Truth table100%1/2
A
A= $env->{"REQUEST_METHOD"}
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 2 | ▶ | my $path = $env->{PATH_INFO} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$env->{"PATH_INFO"} // ""
MC/DC100%0/1
$env->{"PATH_INFO"} // ""
$env->{"PATH_INFO"}
Truth table100%1/2
A
A= $env->{"PATH_INFO"}
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | ▶ | my $query = $env->{QUERY_STRING} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$env->{"QUERY_STRING"} // ""
MC/DC100%0/1
$env->{"QUERY_STRING"} // ""
$env->{"QUERY_STRING"}
Truth table100%1/2
A
A= $env->{"QUERY_STRING"}
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | my $headers = eval { $c->req->headers } || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
eval {
do {
$c->req->headers
}
} || {}
MC/DC100%0/1
eval {
do {
$c->req->headers
}
} || {}
eval {
do {
$c->req->headers
}
}
Truth table100%1/2
A
A= eval {
do {
$c->req->headers
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | my %hdr = map { $_ => $headers->{$_} } keys %$headers; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | ▶ | my $hdr_rows = _rows(\%hdr, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 7 | my ($k) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 7 | ▶ | return $k =~ /\A(?:cookie|authorization)\z/i || $k =~ $REDACT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$k =~ /\A(?:cookie|authorization)\z/i || $k =~ /$REDACT/
MC/DC100%2/2
$k =~ /\A(?:cookie|authorization)\z/i || $k =~ /$REDACT/
$k =~ /\A(?:cookie|authorization)\z/i
$k =~ /$REDACT/
Truth table100%3/3
A || B
A= $k =~ /\A(?:cookie|authorization)\z/iB= $k =~ /$REDACT/
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | }); | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | my $params = eval { scalar $c->params } || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
eval {
do {
scalar $c->params
}
} || {}
MC/DC100%0/1
eval {
do {
scalar $c->params
}
} || {}
eval {
do {
scalar $c->params
}
}
Truth table100%1/2
A
A= eval {
do {
scalar $c->params
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | my %prm; %prm = %$params if ref $params eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | ▶ | for (keys %prm) { delete $prm{$_} if ref $prm{$_} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | my $prm_rows = _rows(\%prm, sub { $_[0] =~ $REDACT }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | my $match = eval { $c->match }; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | my %rt; | |||||||||||||||||||||||||||||||||||||||||
| 218 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | ▶ | if (ref $match eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | for my $k (sort keys %$match) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | my $v = $match->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 222 | # uncoverable branch false count:1 | ||||||||||||||||||||||||||||||||||||||||||
| 223 | # uncoverable branch true count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # uncoverable branch false count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | if (ref $v eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | $rt{"$k.$_"} = $v->{$_} for keys %$v; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | elsif (!ref $v) { $rt{$k} = $v } | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | ▶ | my $rt_rows = _rows(\%rt, sub { 0 }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | my (@app, @plumbing); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | for my $f (@$frames) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | 10 | ▶ | if (_is_plumbing($f)) { push @plumbing, $f } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | else { push @app, $f } | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # a die thrown from inside the framework with no app frame at all | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # still deserves snippets - show everything rather than nothing | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # uncoverable statement count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # uncoverable statement count:3 | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if (!@app && @plumbing) { @app = @plumbing; @plumbing = () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
not @app and @plumbing
MC/DC100%0/2
not @app and @plumbing
not @app
@plumbing
Truth table100%1/3
not(A) and B
A= not @appB= @plumbing
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | my $frame_html = ''; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | for my $f (@app) { | |||||||||||||||||||||||||||||||||||||||||
| 250 | $frame_html .= '<div class="frame"><p>' | ||||||||||||||||||||||||||||||||||||||||||
| 251 | . _e("$f->{file} line $f->{line}") . ' <b>in ' | ||||||||||||||||||||||||||||||||||||||||||
| 252 | . _e($f->{sub}) . '</b></p>' | ||||||||||||||||||||||||||||||||||||||||||
| 253 | . _snippet($f->{file}, $f->{line}) | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | . "</div>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | if (@plumbing) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | $frame_html .= '<details><summary>' | ||||||||||||||||||||||||||||||||||||||||||
| 259 | . scalar(@plumbing) | ||||||||||||||||||||||||||||||||||||||||||
| 260 | . ' framework frame(s)</summary><table>' | ||||||||||||||||||||||||||||||||||||||||||
| 261 | . join('', map { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | '<tr><th>' . _e("$_->{file}:$_->{line}") . '</th><td>' | |||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | . _e($_->{sub}) . "</td></tr>\n" | |||||||||||||||||||||||||||||||||||||||||
| 264 | } @plumbing) | ||||||||||||||||||||||||||||||||||||||||||
| 265 | . '</table></details>' . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | $frame_html = '<p class="none">No frames were captured - the exception ' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | . 'surfaced outside the request scope (a deferred future, most ' | ||||||||||||||||||||||||||||||||||||||||||
| 270 | . 'likely).</p>' unless $frame_html; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | ▶ | my $title = _e((split /\n/, $msg)[0] // 'error'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
(split(/\n/, $msg, 0))[0] // "error"
MC/DC100%0/1
(split(/\n/, $msg, 0))[0] // "error"
(split(/\n/, $msg, 0))[0]
Truth table100%1/2
A
A= (split(/\n/, $msg, 0))[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | my $emsg = _e($msg); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | my ($em, $ep) = (_e($method), _e($path)); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | my $eq = _e(_redacted_query($query)); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | my $qline = length $eq ? "?$eq" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | return <<"HTML"; | |||||||||||||||||||||||||||||||||||||||||
| 280 | <!doctype html> | ||||||||||||||||||||||||||||||||||||||||||
| 281 | <html lang="en"> | ||||||||||||||||||||||||||||||||||||||||||
| 282 | <head> | ||||||||||||||||||||||||||||||||||||||||||
| 283 | <meta charset="utf-8"> | ||||||||||||||||||||||||||||||||||||||||||
| 284 | <title>Punk error: $title</title> | ||||||||||||||||||||||||||||||||||||||||||
| 285 | <style> | ||||||||||||||||||||||||||||||||||||||||||
| 286 | body { margin: 0; font: 15px/1.5 -apple-system, BlinkMacSystemFont, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | "Segoe UI", sans-serif; color: #24292f; background: #f6f8fa; } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | header { background: #b31d28; color: #fff; padding: 1.2rem 2rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | header h1 { margin: 0 0 .4rem; font-size: 1.1rem; font-weight: 600; } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | header pre { margin: 0; font-size: 1rem; white-space: pre-wrap; } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | main { padding: 1.5rem 2rem; max-width: 70rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .05em; | ||||||||||||||||||||||||||||||||||||||||||
| 293 | color: #57606a; margin: 2rem 0 .6rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | table { border-collapse: collapse; width: 100%; background: #fff; | ||||||||||||||||||||||||||||||||||||||||||
| 295 | border: 1px solid #d0d7de; font-size: .85rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | th, td { text-align: left; padding: .35rem .6rem; | ||||||||||||||||||||||||||||||||||||||||||
| 297 | border-bottom: 1px solid #d8dee4; vertical-align: top; } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | th { width: 16rem; font-weight: 600; color: #57606a; } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | .frame { margin-bottom: 1rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | .frame p { margin: 0 0 .3rem; font-size: .85rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | pre.snippet { margin: 0; background: #fff; border: 1px solid #d0d7de; | ||||||||||||||||||||||||||||||||||||||||||
| 302 | padding: .5rem 0; overflow-x: auto; font-size: .8rem; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | line-height: 1.45; } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | pre.snippet span.ln { display: block; padding: 0 .75rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | pre.snippet span.ln.hit { background: #fff1f1; } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | pre.snippet i { font-style: normal; color: #8c959f; user-select: none; } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | .esh-k { color: #cf222e; } .esh-b { color: #8250df; } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | .esh-s { color: #0a3069; } .esh-c { color: #6e7781; } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | .esh-n { color: #0550ae; } .esh-p { color: #953800; } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | .esh-v { color: #24292f; } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | .none { color: #57606a; font-style: italic; } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | details { margin: .6rem 0 1rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | details summary { cursor: pointer; font-size: .85rem; color: #57606a; } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | details table { margin-top: .4rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | footer { padding: 1rem 2rem 2rem; color: #8c959f; font-size: .8rem; } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | </style> | ||||||||||||||||||||||||||||||||||||||||||
| 317 | </head> | ||||||||||||||||||||||||||||||||||||||||||
| 318 | <body> | ||||||||||||||||||||||||||||||||||||||||||
| 319 | <header> | ||||||||||||||||||||||||||||||||||||||||||
| 320 | <h1>$em $ep$qline</h1> | ||||||||||||||||||||||||||||||||||||||||||
| 321 | <pre>$emsg</pre> | ||||||||||||||||||||||||||||||||||||||||||
| 322 | </header> | ||||||||||||||||||||||||||||||||||||||||||
| 323 | <main> | ||||||||||||||||||||||||||||||||||||||||||
| 324 | <h2>Stack</h2> | ||||||||||||||||||||||||||||||||||||||||||
| 325 | $frame_html | ||||||||||||||||||||||||||||||||||||||||||
| 326 | <h2>Route</h2> | ||||||||||||||||||||||||||||||||||||||||||
| 327 | <table>$rt_rows</table> | ||||||||||||||||||||||||||||||||||||||||||
| 328 | <h2>Parameters</h2> | ||||||||||||||||||||||||||||||||||||||||||
| 329 | <table>$prm_rows</table> | ||||||||||||||||||||||||||||||||||||||||||
| 330 | <h2>Request headers</h2> | ||||||||||||||||||||||||||||||||||||||||||
| 331 | <table>$hdr_rows</table> | ||||||||||||||||||||||||||||||||||||||||||
| 332 | </main> | ||||||||||||||||||||||||||||||||||||||||||
| 333 | <footer>Punk $Punk::VERSION in development (opted in via punk dev or | ||||||||||||||||||||||||||||||||||||||||||
| 334 | PUNK_ENV=development) - the production default answers a plain JSON | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 500.</footer> | ||||||||||||||||||||||||||||||||||||||||||
| 336 | </body> | ||||||||||||||||||||||||||||||||||||||||||
| 337 | </html> | ||||||||||||||||||||||||||||||||||||||||||
| 338 | HTML | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | __END__ | ||||||||||||||||||||||||||||||||||||||||||