| 1 | package CGI::Carp::DebugScreen::DefaultView; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = '0.15'; | |||||||||
| 7 | |||||||||||
| 8 | 12 | ▶ | sub as_html { | ||||||||
|
Subroutine
as_html: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 9 | 12 | my ($pkg, %options) = @_; | |||||||||
| 10 | |||||||||||
| 11 | 12 | delete $options{debug_template}; | |||||||||
| 12 | 12 | delete $options{error_template}; | |||||||||
| 13 | |||||||||||
| 14 | 12 | ▶ | $options{debug} ? $pkg->_debug(%options) : $pkg->_error(%options); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 1258 | ▶ | sub _escape { | ||||||||
|
Subroutine
_escape: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1258 | my $str = shift; | |||||||||
| 19 | |||||||||||
| 20 | 1258 | $str =~ s/&/&/g; | |||||||||
| 21 | 1258 | $str =~ s/>/>/g; | |||||||||
| 22 | 1258 | $str =~ s/</</g; | |||||||||
| 23 | 1258 | $str =~ s/"/"/g; | |||||||||
| 24 | |||||||||||
| 25 | 1258 | $str; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 16 | ▶ | sub _navi { | ||||||||
|
Subroutine
_navi: called CC=4 SCAR=13.9
| |||||||||||
| 29 | 16 | my %options = @_; | |||||||||
| 30 | |||||||||||
| 31 | 16 | my $html =<<"EOT"; | |||||||||
| 32 | <div class="navi"> | ||||||||||
| 33 | [<a href="#top">top</a>] | ||||||||||
| 34 | [<a href="#stacktraces">stacktraces</a>] | ||||||||||
| 35 | EOT | ||||||||||
| 36 | 16 | ▶ | if (@{ $options{watchlist} }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 4 | $html .=<<"EOT"; | |||||||||
| 38 | [<a href="#watch">watchlist</a>] | ||||||||||
| 39 | EOT | ||||||||||
| 40 | } | ||||||||||
| 41 | 16 | ▶ | if (@{ $options{modules} }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 4 | $html .=<<"EOT"; | |||||||||
| 43 | [<a href="#modules">modules</a>] | ||||||||||
| 44 | EOT | ||||||||||
| 45 | } | ||||||||||
| 46 | 16 | ▶ | if (@{ $options{environment} }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 4 | $html .=<<"EOT"; | |||||||||
| 48 | [<a href="#environment">environment</a>] | ||||||||||
| 49 | EOT | ||||||||||
| 50 | } | ||||||||||
| 51 | 16 | $html .=<<"EOT"; | |||||||||
| 52 | </div> | ||||||||||
| 53 | EOT | ||||||||||
| 54 | |||||||||||
| 55 | 16 | return $html; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 10 | ▶ | sub _debug { | ||||||||
|
Subroutine
_debug: called CC=11 SCAR=24.0
| |||||||||||
| 59 | 10 | my ($pkg, %options) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 10 | my $error_at = _escape($options{error_at}); | |||||||||
| 62 | |||||||||||
| 63 | 10 | my $html =<<"EOT"; | |||||||||
| 64 | <html> | ||||||||||
| 65 | <head> | ||||||||||
| 66 | <title>Debug Screen</title> | ||||||||||
| 67 | $options{style} | ||||||||||
| 68 | </head> | ||||||||||
| 69 | <body> | ||||||||||
| 70 | <div id="page"> | ||||||||||
| 71 | <a name="top"></a> | ||||||||||
| 72 | <h1>$error_at</h1> | ||||||||||
| 73 | EOT | ||||||||||
| 74 | |||||||||||
| 75 | 10 | ▶ | if ($options{show_raw_error}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 2 | $html .=<<"EOT"; | |||||||||
| 77 | <pre class="raw_error">$options{raw_error}</pre> | ||||||||||
| 78 | EOT | ||||||||||
| 79 | } | ||||||||||
| 80 | else { | ||||||||||
| 81 | 8 | $html .=<<"EOT"; | |||||||||
| 82 | <div class="box"> | ||||||||||
| 83 | $options{error_message} | ||||||||||
| 84 | </div> | ||||||||||
| 85 | EOT | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 10 | $html .= _navi(%options); | |||||||||
| 89 | |||||||||||
| 90 | 10 | $html .=<<"EOT"; | |||||||||
| 91 | <div class="box"> | ||||||||||
| 92 | <h2><a name="stacktraces">Stacktraces</a></h2> | ||||||||||
| 93 | <ul id="stacktraces"> | ||||||||||
| 94 | EOT | ||||||||||
| 95 | |||||||||||
| 96 | 10 | foreach my $stacktrace (@{ $options{stacktraces} }) { | |||||||||
| 97 | 30 | my $caller = _escape($stacktrace->{caller}); | |||||||||
| 98 | 30 | my $line = $stacktrace->{line}; | |||||||||
| 99 | 30 | $html .=<<"EOT"; | |||||||||
| 100 | <li>$caller LINE : $line</li> | ||||||||||
| 101 | <table class="code"> | ||||||||||
| 102 | EOT | ||||||||||
| 103 | |||||||||||
| 104 | 30 | foreach my $line (@{ $stacktrace->{context} }) { | |||||||||
| 105 | 210 | ▶ | if ($line->{hit}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 30 | $html .=<<"EOT"; | |||||||||
| 107 | <tr class="hit"> | ||||||||||
| 108 | EOT | ||||||||||
| 109 | } | ||||||||||
| 110 | else { | ||||||||||
| 111 | 180 | $html .=<<"EOT"; | |||||||||
| 112 | <tr> | ||||||||||
| 113 | EOT | ||||||||||
| 114 | } | ||||||||||
| 115 | 210 | my $line_no = _escape($line->{no}); | |||||||||
| 116 | 210 | my $line_body = _escape($line->{line}); | |||||||||
| 117 | 210 | $html .=<<"EOT"; | |||||||||
| 118 | <td class="num">$line_no:</td><td>$line_body</td> | ||||||||||
| 119 | </tr> | ||||||||||
| 120 | EOT | ||||||||||
| 121 | } | ||||||||||
| 122 | 30 | $html .=<<"EOT"; | |||||||||
| 123 | </table> | ||||||||||
| 124 | EOT | ||||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 10 | $html .=<<"EOT"; | |||||||||
| 128 | </ul> | ||||||||||
| 129 | </div> | ||||||||||
| 130 | EOT | ||||||||||
| 131 | |||||||||||
| 132 | 10 | ▶ | if (@{ $options{watchlist} }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | 2 | $html .= _navi(%options); | |||||||||
| 134 | |||||||||||
| 135 | 2 | $html .=<<"EOT"; | |||||||||
| 136 | <div class="box"> | ||||||||||
| 137 | <h2><a name="watch">Watch List</a></h2> | ||||||||||
| 138 | <ul id="watch"> | ||||||||||
| 139 | EOT | ||||||||||
| 140 | |||||||||||
| 141 | 2 | foreach my $watch (@{ $options{watchlist} }) { | |||||||||
| 142 | 2 | my $key = _escape($watch->{key}); | |||||||||
| 143 | 2 | my $table = $watch->{value}; | |||||||||
| 144 | 2 | $html .=<<"EOT"; | |||||||||
| 145 | <li> | ||||||||||
| 146 | <b>$key</b><br> | ||||||||||
| 147 | <div class="scrollable"> | ||||||||||
| 148 | $table | ||||||||||
| 149 | </div> | ||||||||||
| 150 | </li> | ||||||||||
| 151 | EOT | ||||||||||
| 152 | } | ||||||||||
| 153 | 2 | $html .=<<"EOT"; | |||||||||
| 154 | </ul> | ||||||||||
| 155 | </div> | ||||||||||
| 156 | EOT | ||||||||||
| 157 | } | ||||||||||
| 158 | |||||||||||
| 159 | 10 | ▶ | if (@{ $options{modules} }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | 2 | $html .= _navi(%options); | |||||||||
| 161 | |||||||||||
| 162 | 2 | $html .=<<"EOT"; | |||||||||
| 163 | <div class="box"> | ||||||||||
| 164 | <h2><a name="modules">Included Modules</a></h2> | ||||||||||
| 165 | <ul id="modules"> | ||||||||||
| 166 | EOT | ||||||||||
| 167 | |||||||||||
| 168 | 2 | foreach my $module (@{ $options{modules} }) { | |||||||||
| 169 | 305 | my $package = _escape($module->{package}); | |||||||||
| 170 | 305 | my $file = _escape($module->{file}); | |||||||||
| 171 | |||||||||||
| 172 | 305 | $html .=<<"EOT"; | |||||||||
| 173 | <li>$package ($file)</li> | ||||||||||
| 174 | EOT | ||||||||||
| 175 | } | ||||||||||
| 176 | 2 | $html .=<<"EOT"; | |||||||||
| 177 | </ul> | ||||||||||
| 178 | </div> | ||||||||||
| 179 | EOT | ||||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | 10 | ▶ | if (@{ $options{environment} }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | 2 | $html .= _navi(%options); | |||||||||
| 184 | |||||||||||
| 185 | 2 | $html .=<<"EOT"; | |||||||||
| 186 | <div class="box"> | ||||||||||
| 187 | <h2><a name="environment">Environmental Variables</a></h2> | ||||||||||
| 188 | <table id="environment"> | ||||||||||
| 189 | EOT | ||||||||||
| 190 | |||||||||||
| 191 | 2 | foreach my $env (@{ $options{environment} }) { | |||||||||
| 192 | 68 | my $key = _escape($env->{key}); | |||||||||
| 193 | 68 | my $value = _escape($env->{value}); | |||||||||
| 194 | 68 | $html .=<<"EOT"; | |||||||||
| 195 | <tr> | ||||||||||
| 196 | <td>$key</td><td><div class="scrollable">$value</div><//td> | ||||||||||
| 197 | </tr> | ||||||||||
| 198 | EOT | ||||||||||
| 199 | } | ||||||||||
| 200 | 2 | $html .=<<"EOT"; | |||||||||
| 201 | </table> | ||||||||||
| 202 | </div> | ||||||||||
| 203 | EOT | ||||||||||
| 204 | } | ||||||||||
| 205 | |||||||||||
| 206 | 10 | my $version = _escape($options{version}); | |||||||||
| 207 | 10 | my $view = _escape($options{view}); | |||||||||
| 208 | |||||||||||
| 209 | 10 | $html .=<<"EOT"; | |||||||||
| 210 | <p class="footer">CGI::Carp::DebugScreen $version. Output via $view</p> | ||||||||||
| 211 | </div> | ||||||||||
| 212 | </body> | ||||||||||
| 213 | </html> | ||||||||||
| 214 | EOT | ||||||||||
| 215 | |||||||||||
| 216 | 10 | return $html; | |||||||||
| 217 | } | ||||||||||
| 218 | |||||||||||
| 219 | 2 | ▶ | sub _error { | ||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||
| 220 | 2 | my ($pkg, %options) = @_; | |||||||||
| 221 | |||||||||||
| 222 | my %escaped = map { | ||||||||||
| 223 | 2 | ( $_, _escape($options{$_}) ) | |||||||||
| 224 | } keys %options; | ||||||||||
| 225 | |||||||||||
| 226 | 2 | my $html =<<"EOT"; | |||||||||
| 227 | <html> | ||||||||||
| 228 | <head> | ||||||||||
| 229 | <title>An unexpected error has been detected</title> | ||||||||||
| 230 | $options{style} | ||||||||||
| 231 | </head> | ||||||||||
| 232 | <body> | ||||||||||
| 233 | <div id="page"> | ||||||||||
| 234 | <h1>An unexpected error has been detected</h1> | ||||||||||
| 235 | <p>Sorry for inconvenience.</p> | ||||||||||
| 236 | </div> | ||||||||||
| 237 | </body> | ||||||||||
| 238 | </html> | ||||||||||
| 239 | EOT | ||||||||||
| 240 | |||||||||||
| 241 | 2 | return $html; | |||||||||
| 242 | } | ||||||||||
| 243 | |||||||||||
| 244 | 2 | 1; | |||||||||
| 245 | |||||||||||
| 246 | __END__ | ||||||||||