Simple/Caller.pm

filter: Statementstmt 99.1% 110 / 111 Branchbran 64.2% 18 / 28 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 22 / 22 Podpod 100% 1 / 1 totaltotal 89.3% 160 / 179 CC 25 SCAR 20.3
CC
25
Cov
90%
stack
18.8
_text_table
4.0
_html_table_blank_check
4.0
CRAP 7.6
« Simple/Base/Parser.pm ↑ Summary Simple/Tokenizer.pm »
1 ## no critic (ProhibitUnusedPrivateSubroutines)
2 package Text::Template::Simple::Caller;
3 35 $Text::Template::Simple::Caller::VERSION = '0.91';
4 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 35 ▶use constant PACKAGE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use constant FILENAME => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use constant LINE => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use constant SUBROUTINE => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use constant HASARGS => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use constant WANTARRAY => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 35 ▶use constant EVALTEXT => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 35 ▶use constant IS_REQUIRE => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 35 ▶use constant HINTS => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 35 ▶use constant BITMASK => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 35 ▶use Text::Template::Simple::Util qw( fatal );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 35 ▶use Text::Template::Simple::Constants qw( EMPTY_STRING );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 ▶sub stack {
Subroutine stack: called CC=15 SCAR=29.3
Pod documented
22 4 my $self = shift;
23 4 ▶ my $opt = shift || {};
Condition50%1/2
shift() || {}
l!l
40
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
24 4 ▶ fatal('tts.caller.stack.hash') if ref $opt ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt ne "HASH" 0 4 4
25 4 ▶ my $frame = $opt->{frame} || 0;
Condition50%1/2
$opt->{'frame'} || 0
l!l
40
MC/DC0%0/1
$opt->{'frame'} || 0
$opt->{'frame'}
Truth table50%1/2
A
A= $opt->{'frame'}
Aresult
11
00
26 4 ▶ my $type = $opt->{type} || EMPTY_STRING;
Condition50%1/2
$opt->{'type'} || ''
l!l
40
MC/DC0%0/1
$opt->{'type'} || ''
$opt->{'type'}
Truth table50%1/2
A
A= $opt->{'type'}
Aresult
11
00
27 4 my(@callers, $context);
28  
29 4 ▶ TRACE: while ( my @c = caller ++$frame ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@c) = caller ++$frame) 16 4 20
30  
31 16 INITIALIZE: foreach my $id ( 0 .. $#c ) {
32 176 ▶ next INITIALIZE if $id == WANTARRAY; # can be undef
Branch: 1 branch
BranchTrueFalseTotal
if $id == 5 16 160 176
33 160 ▶ $c[$id] ||= EMPTY_STRING;
Condition100%2/2
$c[$id] ||= ""
l!l
11248
MC/DC100%1/1
$c[$id] ||= ""
$c[$id]
Truth table100%2/2
A
A= $c[$id]
Aresult
11
00
34 }
35  
36 16 ▶ $context = defined $c[WANTARRAY] ? ( $c[WANTARRAY] ? 'LIST' : 'SCALAR' )
Branch: 2 branches
BranchTrueFalseTotal
defined $c[5] ? : 16 0 16
$c[5] ? : 0 16 16
37 : 'VOID'
38 ;
39  
40 16 ▶ push @callers,
Branch: 1 branch
BranchTrueFalseTotal
$c[4] ? : 16 0 16
41 {
42 class => $c[PACKAGE ],
43 file => $c[FILENAME ],
44 line => $c[LINE ],
45 sub => $c[SUBROUTINE],
46 context => $context,
47 isreq => $c[IS_REQUIRE],
48 hasargs => $c[HASARGS ] ? 'YES' : 'NO',
49 evaltext => $c[EVALTEXT ],
50 hints => $c[HINTS ],
51 bitmask => $c[BITMASK ],
52 };
53  
54 }
55  
56 4 ▶ return if ! @callers; # no one called us?
Branch: 1 branch
BranchTrueFalseTotal
unless @callers 0 4 4
57 4 ▶ return reverse @callers if ! $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 4 4
58  
59 4 ▶ if ( $self->can( my $method = '_' . $type ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can(my $method = '_' . $type)) 4 0 4
60 4 return $self->$method( $opt, \@callers );
61 }
62  
63 0 return fatal('tts.caller.stack.type', $type);
64 }
65  
66 2 ▶sub _string {
Subroutine _string: called CC=4 SCAR=13.9
67 2 my $self = shift;
68 2 my $opt = shift;
69 2 my $callers = shift;
70 2 my $is_html = shift;
71  
72 2 ▶ my $name = $opt->{name} ? "FOR $opt->{name} " : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'name'} ? : 2 0 2
73 2 my $rv = qq{[ DUMPING CALLER STACK $name]\n\n};
74  
75 2 foreach my $c ( reverse @{$callers} ) {
76 $rv .= sprintf qq{%s %s() at %s line %s\n},
77 8 @{ $c }{ qw/ context sub file line / }
78 }
79  
80 2 ▶ $rv = "<!-- $rv -->" if $is_html;
Branch: 1 branch
BranchTrueFalseTotal
if $is_html 1 1 2
81 2 return $rv;
82 }
83  
84 1 ▶sub _html_comment {
Subroutine _html_comment: called CC=1 SCAR=0.0
85 1 my($self, @args) = @_;
86 1 return $self->_string( @args, 'add html comment' );
87 }
88  
89 1 ▶sub _html_table {
Subroutine _html_table: called CC=2 SCAR=6.9
90 1 my $self = shift;
91 1 my $opt = shift;
92 1 my $callers = shift;
93 1 my $rv = EMPTY_STRING;
94  
95 1 foreach my $c ( reverse @{ $callers } ) {
96 4 $self->_html_table_blank_check( $c ); # modifies in place
97 4 $rv .= $self->_html_table_row( $c )
98 }
99  
100 1 return $self->_html_table_wrap( $rv );
101 }
102  
103 1 ▶sub _html_table_wrap {
Subroutine _html_table_wrap: called CC=1 SCAR=0.0
104 1 my($self, $content) = @_;
105 1 return <<"HTML";
106 <div id="ttsc-wrapper">
107 <table border = "1"
108 cellpadding = "1"
109 cellspacing = "2"
110 id = "ttsc-dump"
111 >
112 <tr>
113 <td class="ttsc-title">CONTEXT</td>
114 <td class="ttsc-title">SUB</td>
115 <td class="ttsc-title">LINE</td>
116 <td class="ttsc-title">FILE</td>
117 <td class="ttsc-title">HASARGS</td>
118 <td class="ttsc-title">IS_REQUIRE</td>
119 <td class="ttsc-title">EVALTEXT</td>
120 <td class="ttsc-title">HINTS</td>
121 <td class="ttsc-title">BITMASK</td>
122 </tr>
123 $content
124 </table>
125 </div>
126 HTML
127 }
128  
129 4 ▶sub _html_table_row {
Subroutine _html_table_row: called CC=1 SCAR=0.0
130 4 my($self,$c) = @_;
131 4 return <<"HTML";
132 <tr>
133 <td class="ttsc-value">$c->{context}</td>
134 <td class="ttsc-value">$c->{sub}</td>
135 <td class="ttsc-value">$c->{line}</td>
136 <td class="ttsc-value">$c->{file}</td>
137 <td class="ttsc-value">$c->{hasargs}</td>
138 <td class="ttsc-value">$c->{isreq}</td>
139 <td class="ttsc-value">$c->{evaltext}</td>
140 <td class="ttsc-value">$c->{hints}</td>
141 <td class="ttsc-value">$c->{bitmask}</td>
142 </tr>
143 HTML
144 }
145  
146 4 ▶sub _html_table_blank_check {
Subroutine _html_table_blank_check: called CC=4 SCAR=13.9
147 4 my $self = shift;
148 4 my $struct = shift;
149 4 foreach my $id ( keys %{ $struct }) {
150 40 ▶ if ( not defined $struct->{ $id } or $struct->{ $id } eq EMPTY_STRING ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $struct->{$id} or $struct->{$id} eq "") 8 32 40
Condition66%2/3
not defined $struct->{$id} or $struct->{$id} eq ""
l!l&&r!l&&!r
0832
MC/DC50%1/2
not defined $struct->{$id} or $struct->{$id} eq ""
not defined $struct->{$id} $struct->{$id} eq ""
Truth table66%2/3
not(A) or B
A= not defined $struct->{$id}B= $struct->{$id} eq ""
ABresult
1X1
011
000
151 8 $struct->{ $id } = '&#160;';
152 }
153 }
154 4 return;
155 }
156  
157 1 ▶sub _text_table {
Subroutine _text_table: called CC=4 SCAR=13.9
158 1 my $self = shift;
159 1 my $opt = shift;
160 1 my $callers = shift;
161 1 my $ok = eval { require Text::Table; 1; };
162 1 ▶ fatal('tts.caller._text_table.module', $@) if ! $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
163  
164 1 my $table = Text::Table->new( qw(
165 | CONTEXT | SUB | LINE | FILE | HASARGS
166 | IS_REQUIRE | EVALTEXT | HINTS | BITMASK |
167 ));
168  
169 1 my $pipe = q{|};
170 1 foreach my $c ( reverse @{$callers} ) {
171 $table->load(
172 [
173 $pipe, $c->{context},
174 $pipe, $c->{sub},
175 $pipe, $c->{line},
176 $pipe, $c->{file},
177 $pipe, $c->{hasargs},
178 $pipe, $c->{isreq},
179 $pipe, $c->{evaltext},
180 $pipe, $c->{hints},
181 $pipe, $c->{bitmask},
182 4 $pipe
183 ],
184 );
185 }
186  
187 1 ▶ my $name = $opt->{name} ? "FOR $opt->{name} " : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'name'} ? : 1 0 1
188 1 my $top = qq{| DUMPING CALLER STACK $name |\n};
189  
190 1 my $rv = qq{\n} . ( q{-} x (length($top) - 1) ) . qq{\n} . $top
191 . $table->rule( qw( - + ) )
192 . $table->title
193 . $table->rule( qw( - + ) )
194 . $table->body
195 . $table->rule( qw( - + ) )
196 ;
197  
198 1 return $rv;
199 }
200  
201 35 1;
202  
203 __END__
« Simple/Base/Parser.pm ↑ Summary Simple/Tokenizer.pm »