/usr/share/perl5/CGI/Application/Plugin/DebugScreen.pm is in libcgi-application-plugin-viewcode-perl 1.02-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | package CGI::Application::Plugin::DebugScreen;
use 5.006;
use strict;
use warnings;
use HTML::Template;
use Devel::StackTrace;
use IO::File;
use UNIVERSAL::require;
our $VERSION = '1.00';
our $A_CODE = '<a class="package" href="?rm=view_code&module=';
our $A_POD = '<a class="package" href="?rm=view_pod&module=';
our $A_TAIL = '">';
our $A_END = '</a>';
our $TEMPLATE = qq{
<html><!-- HTML::Template -->
<head>
<title>Error in <!-- TMPL_VAR NAME="title" --></title>
<style type="text/css">
body {
font-family: "Bitstream Vera Sans", "Trebuchet MS", Verdana,
Tahoma, Arial, helvetica, sans-serif;
color: #000;
background-color: #E68200;
margin: 0px;
padding: 0px;
}
:link, :link:hover, :visited, :visited:hover {
color: #000;
}
div.box {
position: relative;
background-color: #fff;
border: 1px solid #aaa;
padding: 4px;
margin: 10px;
-moz-border-radius: 10px;
}
div.infos {
background-color: #fff;
border: 3px solid #FFCC99;
padding: 8px;
margin: 4px;
margin-bottom: 10px;
-moz-border-radius: 10px;
overflow: auto;
}
div.infos td.head{
text-align: center;
}
h1 {
margin: 0;
color: #999999;
}
h2 {
margin-top: 0;
margin-bottom: 10px;
font-size: medium;
font-weight: bold;
text-decoration: underline;
}
div.url {
font-size: x-small;
overflow: auto;
}
pre {
font-size: .8em;
line-height: 120%;
font-family: 'Courier New', Courier, monospace;
background-color: #FFCC99;
color: #333;
border: 1px dotted #000;
padding: 5px;
margin: 8px;
overflow: auto;
}
pre b {
font-weight: bold;
color: #000;
background-color: #E68200;
}
h1 a.package {
color: #999999;
}
</style>
</head>
<body>
<div class="box">
<h1><!-- TMPL_VAR NAME="title_a" --></h1>
<div class="url"><!-- TMPL_VAR NAME="url" --></div>
<div class="infos">
<!-- TMPL_VAR NAME="desc" --><br />
</div>
<div class="infos">
<h2>StackTrace</h2>
<table>
<tr>
<th>Package</th>
<th>Line </th>
<th>File </th>
<!-- TMPL_IF NAME="view" -->
<th>View </th>
<!-- /TMPL_IF -->
</tr>
<!-- TMPL_LOOP NAME="stacktrace" -->
<tr>
<td class="head"><!-- TMPL_VAR NAME="package" --></td>
<td class="head"><!-- TMPL_VAR NAME="line" --></td>
<td class="head"><!-- TMPL_VAR NAME="filename" --></td>
<!-- TMPL_IF NAME="view" -->
<td class="head"><!-- TMPL_VAR NAME="code" --> <!-- TMPL_VAR NAME="pod" --></td>
<!-- /TMPL_IF -->
</tr>
<tr>
<td colspan="4"><pre><!-- TMPL_VAR NAME="code_preview" --></pre></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
</div>
</div>
</body>
</html>
};
sub import {
my $self = shift;
my $caller = scalar caller;
$caller->add_callback( 'init', sub{
my $self = shift;
$SIG{__DIE__} = sub{
push @{$self->{__stacktrace}},[Devel::StackTrace->new(ignore_package=>[qw/CGI::Application::Plugin::DebugScreen Carp CGI::Carp/])->frames];
die @_; # rethrow
};
{
no strict 'refs';
*{"$caller\::report"} = \&debug_report;
*{"$caller\::__debugscreen_error"} = sub{
my $self = shift;
if (
exists $INC{'CGI/Application/Plugin/ViewCode.pm'}
&&
! exists $INC{'CGI/Application/Dispatch.pm'}
)
{
$self->{__viewcode}++;
}
$self->report(@_);
};
}
});
$caller->add_callback( 'error', sub{
my $self = shift;
if ( $ENV{CGI_APP_DEBUG} && exists $INC{'CGI/Application/Plugin/ViewCode.pm'} ) {
$self->error_mode('__debugscreen_error');
}
});
if ( ! exists $INC{'CGI/Application/Plugin/ViewCode.pm'} ) {
"CGI::Application::Plugin::ViewCode"->require
or delete $INC{'CGI/Application/Plugin/ViewCode.pm'};
unless ($@) {goto &CGI::Application::Plugin::ViewCode::import}
}
}
sub debug_report{
my $self = shift;
my $desc = '' . shift; #stringify
#useful in case of exception from CGI::Application::Plugin::TT
my $url = $self->query->url(-path_info=>1,-query=>1);
my $title = ref $self || $self;
$title = html_escape($title);
my $title_a = $title;
if ( $self->{__viewcode} ) {
$title_a = $A_CODE . $title . $A_TAIL . $title . $A_END;
}
my $stacks = $self->{__stacktrace}[0];
my @stacktraces;
for my $stack ( @{$stacks} ) {
my %s;
$s{package} = exists $stack->{pkg} ? $stack->{pkg} : $stack->{package};
$s{filename} = exists $stack->{file} ? $stack->{file} : $stack->{filename};
$s{package} = html_escape($s{package});
$s{filename} = html_escape($s{filename});
$s{line} = html_escape($stack->{line});
$s{code_preview} = print_context($s{filename},$s{line},$s{package},$self->{__viewcode});
if ( $self->{__viewcode} && $s{package} ne 'main' ) {
$s{line} = $A_CODE . $s{package} . '#'.$s{line} . $A_TAIL . $s{line} . $A_END;
$s{pod} = $A_POD . $s{package} . $A_TAIL . 'pod' . $A_END;
$s{code} = $A_CODE . $s{package} . $A_TAIL . 'code' . $A_END;
$s{filename} = $A_CODE . $s{package} . $A_TAIL . $s{filename} . $A_END;
$s{package} = $A_CODE . $s{package} . $A_TAIL . $s{package} . $A_END;
$s{view} = $self->{__viewcode};
}
push @stacktraces, \%s;
}
my $t = HTML::Template->new(
scalarref => \$TEMPLATE,
die_on_bad_params => 0,
);
$t->param(
title => $title,
title_a => $title_a,
view => $self->{__viewcode},
url => html_escape($url),
desc => html_escape($desc),
stacktrace => \@stacktraces,
);
$self->header_props( -type => 'text/html' );
return $t->output;
}
sub print_context {
my($file, $linenum, $package, $view) = @_;
my $code;
if (-f $file) {
my $start = $linenum - 3;
my $end = $linenum + 3;
$start = $start < 1 ? 1 : $start;
if (my $fh = IO::File->new($file, 'r')) {
my $cur_line = 0;
while (my $line = <$fh>) {
++$cur_line;
last if $cur_line > $end;
next if $cur_line < $start;
my @tag = $cur_line == $linenum ? qw(<b> </b>) : ("","");
if ( $view && $package ne 'main' && $cur_line == $linenum ) {
my $t_line = $A_CODE.$package.'#'.$linenum.$A_TAIL;
$code .= sprintf(
'%s%s%5d: %s%s%s',
$tag[0], $t_line, $cur_line, html_escape($line), $A_END, $tag[1],
);
}
else {
$code .= sprintf(
'%s%5d: %s%s',
$tag[0], $cur_line, html_escape($line), $tag[1],
);
}
}
}
}
return $code;
}
sub html_escape {
my $str = shift;
$str =~ s/&/&/g;
$str =~ s/</</g;
$str =~ s/>/>/g;
$str =~ s/"/"/g;
return $str;
}
1;
=head1 NAME
CGI::Application::Plugin::DebugScreen - add Debug support to CGI::Application.
=head1 VERSION
This documentation refers to CGI::Application::Plugin::DebugScreen version 1.00
=head1 SYNOPSIS
use CGI::Application::Plugin::DebugScreen;
That is it! The fun starts when a run mode calls C<die>.
=head1 DESCRIPTION
This plug-in adds stack tracing support to CGI::Application similar in style
to the Catalyst debug mode. In the event of the module calling C<die>,
a stack trace of the error is displayed. At each level of the stack
links to the code and documentation are provided.
The stack trace functionality is deactivated unless the B<$ENV{CGI_APP_DEBUG}>
environment variable is set. Therefore when your code is released,
this plug-in does not need to be removed.
The links links to code and documentation are implemented using
L<CGI::Application::Plugin::ViewCode>, which will be loaded automatically
if available. However these links are not supported in conjunction
with L<CGI::Application::Dispatch>.
=head1 DEPENDENCIES
L<strict>
L<warnings>
L<CGI::Application>
L<HTML::Template>
L<Devel::StackTrace>
L<IO::File>
L<CGI::Application::Plugin::ViewCode>
L<UNIVERSAL::require>
=head1 BUGS AND LIMITATIONS
There are no known bugs in this module.
Please report problems to Atsushi Kobayashi (E<lt>nekokak@cpan.orgE<gt>)
Patches are welcome.
=head1 SEE ALSO
L<CGI::Application::Plugin::ViewCode>
L<Sledge::Plugin::DebugScreen>
L<CGI::Carp::DebugScreen>
L<Catalyst::Plugin::StackTrace>
=head1 Thanks To
MATSUNO Tokuhiro (MATSUNO)
Koichi Taniguchi (TANIGUCHI)
Masahiro Nagano (KAZEBURO)
Tomoyuki Misonou
=head1 AUTHOR
Atsushi Kobayashi, E<lt>nekokak@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2006 by Atsushi Kobayashi (E<lt>nekokak@cpan.orgE<gt>). All rights reserved.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See L<perlartistic>.
=cut
|