package CGI::Carp::DebugScreen::DefaultView;
use strict;
use warnings;
our $VERSION = '0.15';
sub as_html {
my ($pkg, %options) = @_;
delete $options{debug_template};
delete $options{error_template};
$options{debug} ? $pkg->_debug(%options) : $pkg->_error(%options);
}
sub _escape {
my $str = shift;
$str =~ s/&/&/g;
$str =~ s/>/>/g;
$str =~ s/</g;
$str =~ s/"/"/g;
$str;
}
sub _navi {
my %options = @_;
my $html =<<"EOT";
[
top]
[
stacktraces]
EOT
if (@{ $options{watchlist} }) {
$html .=<<"EOT";
[
watchlist]
EOT
}
if (@{ $options{modules} }) {
$html .=<<"EOT";
[
modules]
EOT
}
if (@{ $options{environment} }) {
$html .=<<"EOT";
[
environment]
EOT
}
$html .=<<"EOT";
EOT
return $html;
}
sub _debug {
my ($pkg, %options) = @_;
my $error_at = _escape($options{error_at});
my $html =<<"EOT";
$error_at
EOT
if ($options{show_raw_error}) {
$html .=<<"EOT";
$options{raw_error}
EOT
}
else {
$html .=<<"EOT";
$options{error_message}
EOT
}
$html .= _navi(%options);
$html .=<<"EOT";
EOT
foreach my $stacktrace (@{ $options{stacktraces} }) {
my $caller = _escape($stacktrace->{caller});
my $line = $stacktrace->{line};
$html .=<<"EOT";
- $caller LINE : $line
EOT
foreach my $line (@{ $stacktrace->{context} }) {
if ($line->{hit}) {
$html .=<<"EOT";
EOT
}
else {
$html .=<<"EOT";
EOT
}
my $line_no = _escape($line->{no});
my $line_body = _escape($line->{line});
$html .=<<"EOT";
| $line_no: | $line_body |
EOT
}
$html .=<<"EOT";
EOT
}
$html .=<<"EOT";
EOT
if (@{ $options{watchlist} }) {
$html .= _navi(%options);
$html .=<<"EOT";
EOT
foreach my $watch (@{ $options{watchlist} }) {
my $key = _escape($watch->{key});
my $table = $watch->{value};
$html .=<<"EOT";
-
$key
$table
EOT
}
$html .=<<"EOT";
EOT
}
if (@{ $options{modules} }) {
$html .= _navi(%options);
$html .=<<"EOT";
EOT
foreach my $module (@{ $options{modules} }) {
my $package = _escape($module->{package});
my $file = _escape($module->{file});
$html .=<<"EOT";
- $package ($file)
EOT
}
$html .=<<"EOT";
EOT
}
if (@{ $options{environment} }) {
$html .= _navi(%options);
$html .=<<"EOT";
EOT
foreach my $env (@{ $options{environment} }) {
my $key = _escape($env->{key});
my $value = _escape($env->{value});
$html .=<<"EOT";
| $key | $value /td>
|
EOT
}
$html .=<<"EOT";
EOT
}
my $version = _escape($options{version});
my $view = _escape($options{view});
$html .=<<"EOT";
EOT
return $html;
}
sub _error {
my ($pkg, %options) = @_;
my %escaped = map {
( $_, _escape($options{$_}) )
} keys %options;
my $html =<<"EOT";