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