| 1 | package Dancer2::Core::Error; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Class representing fatal errors | ||||||||||||||||||||||||||||||||||
| 3 | 185 | $Dancer2::Core::Error::VERSION = '2.3.0'; | |||||||||||||||||||||||||||||||||
| 4 | 185 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 185 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 185 | ▶ | use Dancer2::Core::Types; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 185 | ▶ | use Dancer2::Core::MIME; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 185 | ▶ | use Dancer2::Core::HTTP; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 185 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 185 | ▶ | use Path::Tiny (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 185 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 185 | ▶ | use Module::Runtime qw/ require_module use_module /; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 185 | ▶ | use Ref::Util qw< is_hashref >; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 185 | ▶ | use Clone qw(clone); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 185 | has app => ( | |||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 18 | isa => InstanceOf['Dancer2::Core::App'], | ||||||||||||||||||||||||||||||||||
| 19 | predicate => 'has_app', | ||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | has show_stacktrace => ( | ||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 24 | isa => Bool, | ||||||||||||||||||||||||||||||||||
| 25 | 186 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 26 | 186 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 186 | ▶ | $self->has_app | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | and return $self->app->setting('show_stacktrace'); | ||||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||||
| 31 | 185 | ); | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | has charset => ( | ||||||||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 35 | isa => Str, | ||||||||||||||||||||||||||||||||||
| 36 | 15 | ▶ | default => sub {'UTF-8'}, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 37 | 185 | ); | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | has type => ( | ||||||||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 41 | isa => Str, | ||||||||||||||||||||||||||||||||||
| 42 | 190 | ▶ | default => sub {'Runtime Error'}, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 43 | 185 | ); | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 185 | has title => ( | |||||||||||||||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 47 | isa => Str, | ||||||||||||||||||||||||||||||||||
| 48 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 49 | builder => '_build_title', | ||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | has censor => ( | ||||||||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 54 | isa => CodeRef, | ||||||||||||||||||||||||||||||||||
| 55 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 56 | 14 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||||
| 57 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 14 | ▶ | if( my $custom = $self->has_app && $self->app->setting('error_censor') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->has_app && $self->app->setting('error_censor')
MC/DC50%1/2
$self->has_app && $self->app->setting('error_censor')
$self->has_app
$self->app->setting('error_censor')
Truth table66%2/3
A && B
A= $self->has_appB= $self->app->setting('error_censor')
| |||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | if( is_hashref $custom ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | die "only one key can be set for the 'error_censor' setting\n" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 63 | if 1 != keys %$custom; | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 1 | my( $class, $args ) = %$custom; | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 1 | my $censor = use_module($class)->new(%$args); | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | return sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 70 | 2 | $censor->censor(@_); | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | 1 | } | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 1 | my $coderef = eval '\&'.$custom; | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | # it's already defined? Nice! We're done | ||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | return $coderef if $coderef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 0 | my $module = $custom =~ s/::[^:]*?$//r; | |||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 0 | require_module($module); | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 0 | return eval '\&'.$custom; | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | # reminder: update POD below if changing the config here | ||||||||||||||||||||||||||||||||||
| 87 | 12 | my $data_censor = use_module('Data::Censor')->new( | |||||||||||||||||||||||||||||||||
| 88 | sensitive_fields => qr/pass|card.?num|pan|secret/i, | ||||||||||||||||||||||||||||||||||
| 89 | replacement => "Hidden (looks potentially sensitive)", | ||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 23 | ▶ | return sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 93 | 23 | $data_censor->censor(@_); | |||||||||||||||||||||||||||||||||
| 94 | 12 | }; | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | 185 | ); | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 179 | ▶ | sub _build_title { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_title: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 99 | 179 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 100 | 179 | my $title = 'Error ' . $self->status; | |||||||||||||||||||||||||||||||||
| 101 | 179 | ▶ | if ( my $msg = Dancer2::Core::HTTP->status_message($self->status) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 178 | $title .= ' - ' . $msg; | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 179 | return $title; | |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 185 | has template => ( | |||||||||||||||||||||||||||||||||
| 109 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 110 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 111 | builder => '_build_error_template', | ||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | 167 | ▶ | sub _build_error_template { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_error_template: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 115 | 167 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | # look for a template named after the status number. | ||||||||||||||||||||||||||||||||||
| 118 | # E.g.: views/404.tt for a TT template | ||||||||||||||||||||||||||||||||||
| 119 | 167 | my $engine = $self->app->template_engine; | |||||||||||||||||||||||||||||||||
| 120 | 167 | ▶ | return $self->status | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 121 | if $engine->pathname_exists( $engine->view_pathname( $self->status ) ); | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | 158 | return; | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 185 | has static_page => ( | |||||||||||||||||||||||||||||||||
| 127 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 128 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 129 | builder => '_build_static_page', | ||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 154 | ▶ | sub _build_static_page { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_static_page: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||
| 133 | 154 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | # TODO there must be a better way to get it | ||||||||||||||||||||||||||||||||||
| 136 | my $public_dir = $ENV{DANCER_PUBLIC} | ||||||||||||||||||||||||||||||||||
| 137 | 154 | ▶ | || ( $self->has_app && $self->app->config->{public_dir} ); | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$ENV{'DANCER_PUBLIC'} || $self->has_app && $self->app->config->{'public_dir'}
$self->has_app and $self->app->config->{"public_dir"}
MC/DC33%1/3
$ENV{'DANCER_PUBLIC'} || $self->has_app && $self->app->config->{'public_dir'}
$ENV{'DANCER_PUBLIC'}
$self->has_app
$self->app->config->{"public_dir"}
Truth table50%2/4
A || B and C
A= $ENV{'DANCER_PUBLIC'}B= $self->has_appC= $self->app->config->{"public_dir"}
| |||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 154 | ▶ | return if !$public_dir; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 152 | my $file = Path::Tiny::path($public_dir)->child( $self->status . '.html' ); | |||||||||||||||||||||||||||||||||
| 142 | 152 | ▶ | return if !$file->is_file; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 5 | return eval { $file->slurp_utf8 }; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 158 | ▶ | sub default_error_page { | ||||||||||||||||||||||||||||||||
|
Subroutine
default_error_page: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 148 | 158 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 158 | require_module('Template::Tiny'); | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 158 | ▶ | my $uri_base = $self->has_app && $self->app->has_request ? | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_app and $self->app->has_request
MC/DC100%2/2
$self->has_app and $self->app->has_request
$self->has_app
$self->app->has_request
Truth table100%3/3
A and B
A= $self->has_appB= $self->app->has_request
| |||||||||||||||||||||||||||||||||||
| 153 | $self->app->request->uri_base : ''; | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | # GH#1001 stack trace if show_stacktrace is true and this is a 'server' error (5xx) | ||||||||||||||||||||||||||||||||||
| 156 | 158 | ▶ | my $show_fullmsg = $self->show_stacktrace && $self->status =~ /^5/; | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->show_stacktrace && $self->status =~ /^5/
MC/DC100%2/2
$self->show_stacktrace && $self->status =~ /^5/
$self->show_stacktrace
$self->status =~ /^5/
Truth table100%3/3
A && B
A= $self->show_stacktraceB= $self->status =~ /^5/
| |||||||||||||||||||||||||||||||||||
| 157 | 158 | ▶ | my $opts = { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
_html_encode($self->message) or "Wooops, something went wrong"
MC/DC100%1/1
_html_encode($self->message) or "Wooops, something went wrong"
_html_encode($self->message)
Truth table100%2/2
A
A= _html_encode($self->message)
| |||||||||||||||||||||||||||||||||||
| 158 | title => $self->title, | ||||||||||||||||||||||||||||||||||
| 159 | charset => $self->charset, | ||||||||||||||||||||||||||||||||||
| 160 | content => $show_fullmsg ? $self->full_message : _html_encode($self->message) || 'Wooops, something went wrong', | ||||||||||||||||||||||||||||||||||
| 161 | uri_base => $uri_base, | ||||||||||||||||||||||||||||||||||
| 162 | }; | ||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | 158 | Template::Tiny->new->process( \<<"END_TEMPLATE", $opts, \my $output ); | |||||||||||||||||||||||||||||||||
| 165 | <!DOCTYPE html> | ||||||||||||||||||||||||||||||||||
| 166 | <html lang="en"> | ||||||||||||||||||||||||||||||||||
| 167 | <head> | ||||||||||||||||||||||||||||||||||
| 168 | <meta charset="[% charset %]"> | ||||||||||||||||||||||||||||||||||
| 169 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> | ||||||||||||||||||||||||||||||||||
| 170 | <title>[% title %]</title> | ||||||||||||||||||||||||||||||||||
| 171 | <link rel="stylesheet" href="[% uri_base %]/css/error.css"> | ||||||||||||||||||||||||||||||||||
| 172 | </head> | ||||||||||||||||||||||||||||||||||
| 173 | <body> | ||||||||||||||||||||||||||||||||||
| 174 | <h1>[% title %]</h1> | ||||||||||||||||||||||||||||||||||
| 175 | <div id="content"> | ||||||||||||||||||||||||||||||||||
| 176 | [% content %] | ||||||||||||||||||||||||||||||||||
| 177 | </div> | ||||||||||||||||||||||||||||||||||
| 178 | </body> | ||||||||||||||||||||||||||||||||||
| 179 | </html> | ||||||||||||||||||||||||||||||||||
| 180 | END_TEMPLATE | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 158 | return $output; | |||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | # status and message are 'rw' to permit modification in core.error.before hooks | ||||||||||||||||||||||||||||||||||
| 186 | has status => ( | ||||||||||||||||||||||||||||||||||
| 187 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 188 | 14 | ▶ | default => sub {500}, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 189 | 185 | isa => Num, | |||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | has message => ( | ||||||||||||||||||||||||||||||||||
| 193 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 194 | isa => Str, | ||||||||||||||||||||||||||||||||||
| 195 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 196 | 33 | ▶ | default => sub { '' }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 197 | 185 | ); | |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | 13 | ▶ | sub full_message { | ||||||||||||||||||||||||||||||||
|
Subroutine
full_message: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 200 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 201 | 13 | my $html_output = "<h2>" . $self->type . "</h2>"; | |||||||||||||||||||||||||||||||||
| 202 | 13 | $html_output .= $self->backtrace; | |||||||||||||||||||||||||||||||||
| 203 | 13 | $html_output .= $self->environment; | |||||||||||||||||||||||||||||||||
| 204 | 13 | return $html_output; | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | 185 | has serializer => ( | |||||||||||||||||||||||||||||||||
| 208 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 209 | isa => Maybe[ConsumerOf['Dancer2::Core::Role::Serializer']], | ||||||||||||||||||||||||||||||||||
| 210 | builder => '_build_serializer', | ||||||||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 187 | ▶ | sub _build_serializer { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_serializer: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 214 | 187 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | 187 | ▶ | $self->has_app && $self->app->has_serializer_engine | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_app and $self->app->has_serializer_engine
MC/DC100%2/2
$self->has_app and $self->app->has_serializer_engine
$self->has_app
$self->app->has_serializer_engine
Truth table100%3/3
A and B
A= $self->has_appB= $self->app->has_serializer_engine
| |||||||||||||||||||||||||||||||||||
| 217 | and return $self->app->serializer_engine; | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 177 | return; | |||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | 190 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 223 | 190 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 190 | ▶ | $self->has_app && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 226 | $self->app->execute_hook( 'core.error.init', $self ); | ||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | has exception => ( | ||||||||||||||||||||||||||||||||||
| 230 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 231 | isa => Str, | ||||||||||||||||||||||||||||||||||
| 232 | predicate => 1, | ||||||||||||||||||||||||||||||||||
| 233 | 32 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 234 | # Until we properly support exception objects, we shouldn't barf on | ||||||||||||||||||||||||||||||||||
| 235 | # them because that hides the actual error, if object overloads "", | ||||||||||||||||||||||||||||||||||
| 236 | # which most exception objects do, this will result in a nicer string. | ||||||||||||||||||||||||||||||||||
| 237 | # other references will produce a meaningless error, but that is | ||||||||||||||||||||||||||||||||||
| 238 | # better than a meaningless stacktrace | ||||||||||||||||||||||||||||||||||
| 239 | 32 | return "$_[0]" | |||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||
| 241 | 185 | ); | |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | has response => ( | ||||||||||||||||||||||||||||||||||
| 244 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 245 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 246 | 180 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 247 | 180 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 248 | 180 | my $serializer = $self->serializer; | |||||||||||||||||||||||||||||||||
| 249 | # include server tokens in response ? | ||||||||||||||||||||||||||||||||||
| 250 | my $no_server_tokens = $self->has_app | ||||||||||||||||||||||||||||||||||
| 251 | ? $self->app->config->{'no_server_tokens'} | ||||||||||||||||||||||||||||||||||
| 252 | : defined $ENV{DANCER_NO_SERVER_TOKENS} | ||||||||||||||||||||||||||||||||||
| 253 | ? $ENV{DANCER_NO_SERVER_TOKENS} | ||||||||||||||||||||||||||||||||||
| 254 | 180 | ▶ | : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 255 | 180 | ▶ | return Dancer2::Core::Response->new( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 256 | mime_type => $self->has_app ? $self->app->mime_type : Dancer2::Core::MIME->new(), | ||||||||||||||||||||||||||||||||||
| 257 | server_tokens => !$no_server_tokens, | ||||||||||||||||||||||||||||||||||
| 258 | ( serializer => $serializer )x!! $serializer | ||||||||||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||
| 261 | 185 | ); | |||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | has content_type => ( | ||||||||||||||||||||||||||||||||||
| 264 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 265 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 266 | 182 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 267 | 182 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 268 | 182 | ▶ | $self->serializer | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 269 | ? $self->serializer->content_type | ||||||||||||||||||||||||||||||||||
| 270 | : 'text/html' | ||||||||||||||||||||||||||||||||||
| 271 | }, | ||||||||||||||||||||||||||||||||||
| 272 | 185 | ); | |||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | 185 | has content => ( | |||||||||||||||||||||||||||||||||
| 275 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 276 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 277 | builder => '_build_content', | ||||||||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||
| 280 | 183 | ▶ | sub _build_content { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_content: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||
| 281 | 183 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||
| 283 | # return a hashref if a serializer is available | ||||||||||||||||||||||||||||||||||
| 284 | 183 | ▶ | if ( $self->serializer ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 285 | 12 | my $content = { | |||||||||||||||||||||||||||||||||
| 286 | message => $self->message, | ||||||||||||||||||||||||||||||||||
| 287 | title => $self->title, | ||||||||||||||||||||||||||||||||||
| 288 | status => $self->status, | ||||||||||||||||||||||||||||||||||
| 289 | }; | ||||||||||||||||||||||||||||||||||
| 290 | 12 | ▶ | $content->{exception} = $self->exception | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 291 | if $self->has_exception; | ||||||||||||||||||||||||||||||||||
| 292 | 12 | return $content; | |||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | # otherwise we check for a template, for a static file, | ||||||||||||||||||||||||||||||||||
| 296 | # for configured error_template, and, if all else fails, | ||||||||||||||||||||||||||||||||||
| 297 | # the default error page | ||||||||||||||||||||||||||||||||||
| 298 | 171 | ▶ | if ( $self->has_app and $self->template ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_app and $self->template
MC/DC100%2/2
$self->has_app and $self->template
$self->has_app
$self->template
Truth table100%3/3
A and B
A= $self->has_appB= $self->template
| |||||||||||||||||||||||||||||||||||
| 299 | # Render the template using apps' template engine. | ||||||||||||||||||||||||||||||||||
| 300 | # This may well be what caused the initial error, in which | ||||||||||||||||||||||||||||||||||
| 301 | # case we fall back to static page if any error was thrown. | ||||||||||||||||||||||||||||||||||
| 302 | # Note: this calls before/after render hooks. | ||||||||||||||||||||||||||||||||||
| 303 | 9 | my $content = eval { | |||||||||||||||||||||||||||||||||
| 304 | 9 | $self->app->template( | |||||||||||||||||||||||||||||||||
| 305 | $self->template, | ||||||||||||||||||||||||||||||||||
| 306 | { title => $self->title, | ||||||||||||||||||||||||||||||||||
| 307 | content => $self->message, | ||||||||||||||||||||||||||||||||||
| 308 | exception => $self->exception, | ||||||||||||||||||||||||||||||||||
| 309 | status => $self->status, | ||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||
| 311 | ); | ||||||||||||||||||||||||||||||||||
| 312 | }; | ||||||||||||||||||||||||||||||||||
| 313 | 9 | ▶ | $@ && $self->app->engine('logger')->log( warning => $@ ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | # return rendered content unless there was an error. | ||||||||||||||||||||||||||||||||||
| 316 | 9 | ▶ | return $content if defined $content; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | # It doesn't make sense to return a static page for a 500 if show_stacktrace is on | ||||||||||||||||||||||||||||||||||
| 320 | 167 | ▶ | if ( !($self->show_stacktrace && $self->status eq '500') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->show_stacktrace and $self->status eq 500
MC/DC100%2/2
$self->show_stacktrace and $self->status eq 500
$self->show_stacktrace
$self->status eq 500
Truth table100%3/3
A and B
A= $self->show_stacktraceB= $self->status eq 500
| |||||||||||||||||||||||||||||||||||
| 321 | 154 | ▶ | if ( my $content = $self->static_page ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 322 | 5 | return $content; | |||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | 162 | ▶ | if ($self->has_app && $self->app->config->{error_template}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_app and $self->app->config->{"error_template"}
MC/DC100%2/2
$self->has_app and $self->app->config->{"error_template"}
$self->has_app
$self->app->config->{"error_template"}
Truth table100%3/3
A and B
A= $self->has_appB= $self->app->config->{"error_template"}
| |||||||||||||||||||||||||||||||||||
| 327 | 4 | my $content = eval { | |||||||||||||||||||||||||||||||||
| 328 | $self->app->template( | ||||||||||||||||||||||||||||||||||
| 329 | $self->app->config->{error_template}, | ||||||||||||||||||||||||||||||||||
| 330 | 4 | { title => $self->title, | |||||||||||||||||||||||||||||||||
| 331 | content => $self->message, | ||||||||||||||||||||||||||||||||||
| 332 | exception => $self->exception, | ||||||||||||||||||||||||||||||||||
| 333 | status => $self->status, | ||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||
| 335 | ); | ||||||||||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||||||||
| 337 | 4 | ▶ | $@ && $self->app->engine('logger')->log( warning => $@ ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||
| 339 | # return rendered content unless there was an error. | ||||||||||||||||||||||||||||||||||
| 340 | 4 | ▶ | return $content if defined $content; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | 158 | return $self->default_error_page; | |||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | 182 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 347 | 182 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 348 | 182 | ▶ | $self->response(shift) if @_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||
| 350 | 182 | ▶ | $self->response | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 351 | or croak "error has no response to throw at"; | ||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||
| 353 | 182 | ▶ | $self->has_app && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 354 | $self->app->execute_hook( 'core.error.before', $self ); | ||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||
| 356 | 182 | my $message = $self->content; | |||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | 182 | $self->response->status( $self->status ); | |||||||||||||||||||||||||||||||||
| 359 | 182 | $self->response->content_type( $self->content_type ); | |||||||||||||||||||||||||||||||||
| 360 | 182 | ▶ | $self->response->charset( $self->charset ) if defined $self->charset; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 361 | 182 | $self->response->content($message); | |||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||
| 363 | 182 | ▶ | $self->has_app && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 364 | $self->app->execute_hook('core.error.after', $self->response); | ||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||
| 366 | 182 | $self->response->is_halted(1); | |||||||||||||||||||||||||||||||||
| 367 | 182 | return $self->response; | |||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||
| 370 | 13 | ▶ | sub backtrace { | ||||||||||||||||||||||||||||||||
|
Subroutine
backtrace: called CC=14 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 371 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | 13 | my $message = $self->message; | |||||||||||||||||||||||||||||||||
| 374 | 13 | ▶ | if ($self->exception) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 375 | 11 | ▶ | $message .= "\n" if $message; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 376 | 11 | $message .= $self->exception; | |||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||
| 378 | 13 | ▶ | $message ||= 'Wooops, something went wrong'; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$message ||= "Wooops, something went wrong"
MC/DC0%0/1
$message ||= "Wooops, something went wrong"
$message
Truth table50%1/2
A
A= $message
| |||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||
| 380 | 13 | my $html = '<pre class="error">' . _html_encode($message) . "</pre>\n"; | |||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | # the default perl warning/error pattern | ||||||||||||||||||||||||||||||||||
| 383 | 13 | my ($file, $line) = $message =~ /at (\S+) line (\d+)/; | |||||||||||||||||||||||||||||||||
| 384 | # the Devel::SimpleTrace pattern | ||||||||||||||||||||||||||||||||||
| 385 | 13 | ▶ | ($file, $line) = $message =~ /at.*\((\S+):(\d+)\)/ unless $file and $line; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file and $line
MC/DC50%1/2
$file and $line
$file
$line
Truth table66%2/3
A and B
A= $fileB= $line
| |||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | # no file/line found, cannot open a file for context | ||||||||||||||||||||||||||||||||||
| 388 | 13 | ▶ | return $html unless $file and $line; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file and $line
MC/DC50%1/2
$file and $line
$file
$line
Truth table66%2/3
A and B
A= $fileB= $line
| |||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||
| 390 | # file and line are located, let's read the source Luke! | ||||||||||||||||||||||||||||||||||
| 391 | 4 | my $path = Path::Tiny::path($file); | |||||||||||||||||||||||||||||||||
| 392 | 4 | ▶ | return $html if !$path->is_file; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||
| 394 | 4 | my @lines; | |||||||||||||||||||||||||||||||||
| 395 | 4 | ▶ | eval { @lines = $path->lines_utf8; 1; } or return $html; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | 4 | $html .= qq|<div class="title">$file around line $line</div>|; | |||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||
| 399 | # get 5 lines of context | ||||||||||||||||||||||||||||||||||
| 400 | 4 | ▶ | my $start = $line - 5 > 1 ? $line - 5 : 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 401 | 4 | ▶ | my $stop = $line + 5 < @lines ? $line + 5 : @lines; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | 4 | $html .= qq|<pre class="content"><table class="context">\n|; | |||||||||||||||||||||||||||||||||
| 404 | 4 | for my $l ($start .. $stop) { | |||||||||||||||||||||||||||||||||
| 405 | 44 | chomp $lines[$l - 1]; | |||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | 44 | ▶ | $html .= $l == $line ? '<tr class="errline">' : '<tr>'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 408 | 44 | $html .= "<th>$l</th><td>" . _html_encode($lines[$l - 1]) . "</td></tr>\n"; | |||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||
| 410 | 4 | $html .= "</table></pre>\n"; | |||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||
| 412 | 4 | return $html; | |||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | 27 | ▶ | sub dumper { | ||||||||||||||||||||||||||||||||
|
Subroutine
dumper: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 416 | 27 | my ($self,$obj) = @_; | |||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||
| 418 | # Take a copy of the data, so we can mask sensitive-looking stuff: | ||||||||||||||||||||||||||||||||||
| 419 | 27 | my $data = clone($obj); | |||||||||||||||||||||||||||||||||
| 420 | 27 | my $censored = $self->censor->( $data ); | |||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||
| 422 | #use Data::Dumper; | ||||||||||||||||||||||||||||||||||
| 423 | 27 | my $dd = Data::Dumper->new( [ $data ] ); | |||||||||||||||||||||||||||||||||
| 424 | 27 | my $hash_separator = ' @@!%,+$$#._(-- '; # Very unlikely string to exist already | |||||||||||||||||||||||||||||||||
| 425 | 27 | my $prefix_padding = ' #+#+@%.,$_-!(( '; # Very unlikely string to exist already | |||||||||||||||||||||||||||||||||
| 426 | 27 | $dd->Terse(1)->Quotekeys(0)->Indent(1)->Sortkeys(1)->Pair($hash_separator)->Pad($prefix_padding); | |||||||||||||||||||||||||||||||||
| 427 | 27 | my $content = _html_encode( $dd->Dump ); | |||||||||||||||||||||||||||||||||
| 428 | 27 | $content =~ s/^.+//; # Remove the first line | |||||||||||||||||||||||||||||||||
| 429 | 27 | $content =~ s/\n.+$//; # Remove the last line | |||||||||||||||||||||||||||||||||
| 430 | 27 | $content =~ s/^\Q$prefix_padding\E //gm; # Remove the padding | |||||||||||||||||||||||||||||||||
| 431 | 27 | $content =~ s{^(\s*)(.+)\Q$hash_separator}{$1<span class="key">$2</span> => }gm; | |||||||||||||||||||||||||||||||||
| 432 | 27 | ▶ | if ($censored) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 433 | 13 | $content | |||||||||||||||||||||||||||||||||
| 434 | .= "\n\nNote: Values of $censored sensitive-looking keys hidden\n"; | ||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||
| 436 | 27 | return $content; | |||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||
| 439 | 19 | ▶ | sub environment { | ||||||||||||||||||||||||||||||||
|
Subroutine
environment: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 440 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||
| 442 | 19 | my $stack = $self->get_caller; | |||||||||||||||||||||||||||||||||
| 443 | 19 | ▶ | my $settings = $self->has_app && $self->app->settings; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->has_app && $self->app->settings
MC/DC50%1/2
$self->has_app && $self->app->settings
$self->has_app
$self->app->settings
Truth table66%2/3
A && B
A= $self->has_appB= $self->app->settings
| |||||||||||||||||||||||||||||||||||
| 444 | 19 | ▶ | my $session = $self->has_app && $self->app->_has_session && $self->app->session->data; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->has_app && $self->app->_has_session && $self->app->session->data
$self->has_app and $self->app->_has_session
MC/DC66%2/3
$self->has_app && $self->app->_has_session && $self->app->session->data
$self->has_app
$self->app->_has_session
$self->app->session->data
Truth table75%3/4
A and B && C
A= $self->has_appB= $self->app->_has_sessionC= $self->app->session->data
| |||||||||||||||||||||||||||||||||||
| 445 | 19 | ▶ | my $env = $self->has_app && $self->app->has_request && $self->app->request->env; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->has_app && $self->app->has_request && $self->app->request->env
$self->has_app and $self->app->has_request
MC/DC66%2/3
$self->has_app && $self->app->has_request && $self->app->request->env
$self->has_app
$self->app->has_request
$self->app->request->env
Truth table75%3/4
A and B && C
A= $self->has_appB= $self->app->has_requestC= $self->app->request->env
| |||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||
| 447 | # Get a sanitised dump of the settings, session and environment | ||||||||||||||||||||||||||||||||||
| 448 | 19 | ▶ | $_ = $_ ? $self->dumper($_) : '<i>undefined</i>' for $settings, $session, $env; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||
| 450 | 19 | return <<"END_HTML"; | |||||||||||||||||||||||||||||||||
| 451 | <div class="title">Stack</div><pre class="content">$stack</pre> | ||||||||||||||||||||||||||||||||||
| 452 | <div class="title">Settings</div><pre class="content">$settings</pre> | ||||||||||||||||||||||||||||||||||
| 453 | <div class="title">Session</div><pre class="content">$session</pre> | ||||||||||||||||||||||||||||||||||
| 454 | <div class="title">Environment</div><pre class="content">$env</pre> | ||||||||||||||||||||||||||||||||||
| 455 | END_HTML | ||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||
| 458 | 19 | ▶ | sub get_caller { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_caller: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 459 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 460 | 19 | my @stack; | |||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||
| 462 | 19 | my $deepness = 0; | |||||||||||||||||||||||||||||||||
| 463 | 19 | ▶ | while ( my ( $package, $file, $line ) = caller( $deepness++ ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 464 | 390 | push @stack, "$package in $file l. $line"; | |||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||
| 467 | 19 | return join( "\n", reverse(@stack) ); | |||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||
| 470 | # private | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | # Replaces the entities that are illegal in (X)HTML. | ||||||||||||||||||||||||||||||||||
| 473 | 229 | ▶ | sub _html_encode { | ||||||||||||||||||||||||||||||||
|
Subroutine
_html_encode: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 474 | 229 | my $value = shift; | |||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||
| 476 | 229 | ▶ | return if !defined $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||
| 478 | 229 | $value =~ s/&/&/g; | |||||||||||||||||||||||||||||||||
| 479 | 229 | $value =~ s/</</g; | |||||||||||||||||||||||||||||||||
| 480 | 229 | $value =~ s/>/>/g; | |||||||||||||||||||||||||||||||||
| 481 | 229 | $value =~ s/'/'/g; | |||||||||||||||||||||||||||||||||
| 482 | 229 | $value =~ s/"/"/g; | |||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||
| 484 | 229 | return $value; | |||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||
| 487 | 185 | 1; | |||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | __END__ | ||||||||||||||||||||||||||||||||||