InteractiveDebugger/HTML.pm

filter: Statementstmt 38.8% 26 / 67 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.4% 5 / 13 Podpod 0.0% 0 / 8 totaltotal 29.8% 31 / 104 CC 10 SCAR 18.4
CC
10
Cov
32%
render_source
12.0
render_summary
12.0
encode_html
6.0
CRAP 6.3
« InteractiveDebugger.pm ↑ Summary
1 package Plack::Middleware::InteractiveDebugger::HTML;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our @EXPORT = qw( render_full render_source encode_html );
7  
8 1 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my $header = <<EOF;
11 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
12 "http://www.w3.org/TR/html4/loose.dtd">
13 <html>
14 <head>
15 <title>%(title) // Plack Interactive Debugger</title>
16 <link rel="stylesheet" href="%(script_name)/__debugger__/res/style.css" type="text/css">
17 <script type="text/javascript" src="%(script_name)/__debugger__/res/jquery.min.js"></script>
18 <script type="text/javascript" src="%(script_name)/__debugger__/res/debugger.js"></script>
19 <script type="text/javascript">
20 var APP_BASE = '%(script_name)',
21 TRACEBACK = %(traceback_id),
22 CONSOLE_MODE = %(console),
23 EVALEX = %(evalex);
24 </script>
25 </head>
26 <body>
27 <div class="debugger">
28 EOF
29  
30 1 my $footer = <<EOF;
31 <div class="footer">
32 Brought to you by <strong class="arthur">DON'T PANIC</strong>, your
33 friendly Plack powered stacktrace interpreter, inspired by Werkzeug.
34 </div>
35 </div>
36 </body>
37 </html>
38 EOF
39  
40 1 my $page_html = $header . <<EOF . $footer;
41 <h1>%(exception_type)</h1>
42 <div class="detail">
43 <p class="errormsg">%(exception)</p>
44 </div>
45 <h2 class="traceback">StackTrace <em>(most recent call first)</em></h2>
46 %(summary)
47 <div class="plain">
48 <p>
49 This is the Copy/Paste friendly version of the stacktrace.
50 </p>
51 <textarea cols="50" rows="10" name="code" readonly>%(plaintext)</textarea>
52 </form>
53 </div>
54 <div class="explanation">
55 The debugger caught an exception in your PSGI application. You can now
56 look at the stacktrace which led to the error. <span class="nojavascript">
57 If you enable JavaScript you can also use additional features such as code
58 execution and much more.</span>
59 </div>
60 EOF
61  
62 1 my $console_html = $header . <<EOF . $footer;
63 <h1>Interactive Console</h1>
64 <div class="explanation">
65 In this console you can execute Perl expressions in the context of the
66 application.
67 </div>
68 <div class="console"><div class="inner">The Console requires JavaScript.</div></div>
69 EOF
70  
71 1 my $summary_html = <<EOF;
72 <div class="%(classes)">
73 StackTrace <em>(most recent call first)</em>
74 <ul>%(frames)</ul>
75 </div>
76 EOF
77  
78 1 my $frame_html = <<EOF;
79 <div class="frame" id="frame-%(id)">
80 <h4>File <cite class="filename">"%(filename)"</cite>,
81 line <em class="line">%(lineno)</em>,
82 in <code class="function">%(function_name)</code></h4>
83 <pre>%(current_line)</pre>
84 </div>
85 EOF
86  
87 1 my $source_table_html = '<table class=source>%(source)</table>';
88  
89 1 my $source_line_html = <<EOF;
90 <tr class="%(classes)">
91 <td class=lineno>%(lineno)</td>
92 <td>%(code)</td>
93 </tr>
94 EOF
95  
96 1 ▶no warnings 'qw';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 my %enc = qw( & &amp; > &gt; < &lt; " &quot; ' &#39; );
98  
99 0 ▶sub encode_html {
Subroutine encode_html: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my $str = shift;
101 0 ▶ $str =~ s/([^\x00-\x21\x23-\x25\x28-\x3b\x3d\x3f-\xff])/$enc{$1} || '&#' . ord($1) . ';' /ge;
Condition0%0/2
$enc{$1} || '&#' . ord($1) . ';'
l!l
00
MC/DC0%0/1
$enc{$1} || '&#' . ord($1) . ';'
$enc{$1}
Truth table0%0/2
A
A= $enc{$1}
Aresult
11
00
102 0 utf8::downgrade($str);
103 0 $str;
104 }
105  
106 0 ▶sub render {
Subroutine render: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my($html, $vars) = @_;
108 0 $html =~ s/%\((.*?)\)/$vars->{$1}/g;
109 0 $html;
110 }
111  
112 0 ▶sub current_line {
Subroutine current_line: not called CC=2 SCAR=17.9
Pod undocumented
113 0 my $frame = shift;
114  
115 0 ▶ open my $fh, "<", $frame->filename or return '';
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $frame->filename or return "" 0 0 0
116 0 my @lines = <$fh>;
117  
118 0 my $line = $lines[$frame->line-1];
119 0 $line =~ s/^\s+//;
120 0 $line;
121 }
122  
123 0 ▶sub render_frame {
Subroutine render_frame: not called CC=2 SCAR=17.9
Pod undocumented
124 0 my($trace, $idx) = @_;
125  
126 0 my $frame = $trace->frame($idx);
127  
128 0 ▶ render $frame_html, {
Branch: 1 branch
BranchTrueFalseTotal
$frame->subroutine ? : 0 0 0
129 id => refaddr($trace) . "-" . $idx,
130 filename => encode_html($frame->filename),
131 lineno => $frame->line,
132 function_name => $frame->subroutine ? encode_html($frame->subroutine) : '',
133 current_line => current_line($frame),
134 };
135 }
136  
137 0 ▶sub render_line {
Subroutine render_line: not called CC=2 SCAR=17.9
Pod undocumented
138 0 my($frame, $line, $lineno) = @_;
139  
140 0 my @classes = ('line');
141 0 ▶ push @classes, 'current' if $frame->line == $lineno;
Branch: 1 branch
BranchTrueFalseTotal
if $frame->line == $lineno 0 0 0
142  
143 0 render $source_line_html, {
144 classes => join(" ", @classes),
145 lineno => $lineno,
146 code => encode_html($line),
147 };
148 }
149  
150 0 ▶sub render_source {
Subroutine render_source: not called CC=3 SCAR=24.8
Pod undocumented
151 0 my $frame = shift;
152  
153 0 my $source;
154  
155 0 ▶ open my $fh, "<", $frame->filename or return '';
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $frame->filename or return "" 0 0 0
156 0 my @lines = <$fh>;
157  
158 0 my $lineno = 1;
159 0 for my $line (@lines) {
160 0 $source .= render_line $frame, $line, $lineno++;
161 0 $source .= "\n";
162 }
163  
164 0 render $source_table_html, { source => $source };
165 }
166  
167 0 ▶sub render_summary {
Subroutine render_summary: not called CC=3 SCAR=24.8
Pod undocumented
168 0 my $trace = shift;
169  
170 0 my @classes = ('traceback');
171 0 ▶ unless ($trace->frames) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trace->frames) 0 0 0
172 0 push @classes, 'noframe-traceback';
173 }
174  
175 0 my $out;
176 0 for my $idx (0..$trace->frame_count-1) {
177 0 $out .= '<li>' . render_frame($trace, $idx);
178 }
179  
180 0 render $summary_html, {
181 classes => join(" ", @classes),
182 frames => $out,
183 };
184 }
185  
186 0 ▶sub render_full {
Subroutine render_full: not called CC=2 SCAR=17.9
Pod undocumented
187 0 my($env, $trace) = @_;
188 0 my $msg = encode_html($trace->frame(0)->as_string(1));
189 render $page_html, {
190 script_name => $env->{SCRIPT_NAME},
191 0 ▶ evalex => 'true',
Condition0%0/2
ref(($trace->frame(0)->args)[0]) || 'Error'
l!l
00
MC/DC0%0/1
ref(($trace->frame(0)->args)[0]) || 'Error'
ref(($trace->frame(0)->args)[0])
Truth table0%0/2
A
A= ref(($trace->frame(0)->args)[0])
Aresult
11
00
192 console => 'false',
193 title => $msg,
194 exception => $msg,
195 exception_type => ref(($trace->frame(0)->args)[0]) || "Error",
196 summary => render_summary($trace),
197 plaintext => $trace->as_string,
198 traceback_id => refaddr($trace),
199 };
200 }
201  
202 1 1;
« InteractiveDebugger.pm ↑ Summary