Inspect/Plugin/CallStack.pm untested

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 121 CC 9 SCAR 28.6
CC
9
Cov
0%
print_lexicals
42.0
print_trace
12.0
process
6.0
CRAP 17.4
1 package CGI::Inspect::Plugin::CallStack;
2  
3 use strict;
4 use base 'CGI::Inspect::Plugin';
5 use Devel::StackTrace::WithLexicals;
6 use Data::Dumper;
7 use CGI qw( escapeHTML );
8  
9 sub new {
10 my $class = shift;
11 my $self = $class->SUPER::new(@_);
12 $self->{trace} = Devel::StackTrace::WithLexicals->new();
13 return $self;
14 }
15  
16 sub print_trace {
17 my $self = shift;
18 my $output = "<div class=dialog id=stacktrace title='Stacktrace'><ul>";
19 my $trace = $self->{trace};
20 $trace->reset_pointer;
21 my $frame_index = 0;
22 my $frame;
23 while($frame = $trace->next_frame) {
24 last if $frame->package() !~ /^(Continuity|Coro|CGI::Inspect)/
25 || $frame->subroutine() eq 'CGI::Inspect::inspect';
26 $frame_index++;
27 }
28 while($frame) {
29 my $next_frame = $trace->next_frame;
30 my $subname = $next_frame ? $next_frame->subroutine : '[GLOBAL]';
31 $output .= "<li>$subname"
32 . " (" . $frame->filename . ":" . $frame->line . ")"
33 ;
34 $output .= $self->print_lexicals($frame->lexicals, $frame_index);
35 $output .= "</li>";
36 $frame = $next_frame;
37 $frame_index++;
38 }
39 $output .= "</ul></div>";
40 return $output;
41 }
42  
43 sub get_field_name {
44 return time() . rand();
45 }
46  
47 sub print_lexicals {
48 my ($self, $lexicals, $frame_index) = @_;
49 my $output = '<ul>';
50 local $Data::Dumper::Terse = 1;
51 local $Data::Dumper::Indent = 1;
52
53 foreach my $var (sort keys %$lexicals) {
54 my $val;
55 if(ref $lexicals->{$var} eq 'REF' || ref $lexicals->{$var} eq 'SCALAR') {
56 $val = Dumper(${ $lexicals->{$var} });
57 } else {
58 $val = Dumper( $lexicals->{$var} );
59 }
60 chomp $val;
61 $val = escapeHTML($val);
62 my $edit_link = $self->request->callback_link(
63 "$var" => sub {
64 my $save_button = $self->request->callback_submit(
65 Save => sub {
66 my $val = $self->param('blah');
67 $val = eval($val);
68 unless ($@) {
69 if(ref $lexicals->{$var} eq 'REF' || ref $lexicals->{$var} eq 'SCALAR') {
70 ${ $lexicals->{$var} } = $val;
71 } elsif(ref $lexicals->{$var} eq 'ARRAY') {
72 @{ $lexicals->{$var} } = @{ $val };
73 } elsif(ref $lexicals->{$var} eq 'HASH') {
74 %{ $lexicals->{$var} } = %{ $val };
75 }
76 }
77 }
78 );
79 $self->{output} = qq{
80 <div class=dialog id=stacktrace title='Stacktrace'>
81 $var = <textarea name=blah style="width: 100%; height: 80%">$val</textarea><br>
82 $save_button
83 <input type=submit name=cancel value="Cancel">
84 </div>
85 };
86 }
87 );
88 $output .= qq{
89 <li>
90 <table border=0>
91 <tr><td valign=top>$edit_link =</td>
92 <td valign=top><pre>$val</pre></td>
93 </table>
94 </li>};
95 }
96  
97 $output .= "</ul>";
98 return $output;
99 }
100  
101  
102 sub process {
103 my ($self) = @_;
104 if($self->{output}) {
105 my $output = $self->{output};
106 $self->{output} = undef;
107 return $output;
108 }
109 return $self->print_trace;
110 }
111  
112 1;
113