Subs.pm

filter: Statementstmt 72.6% 77 / 106 Branchbran 76.4% 26 / 34 Conditioncond 70.0% 21 / 30 MC/DCmcdc 55.5% 10 / 18 Subroutinesub 70.0% 14 / 20 Podpod 100% 4 / 4 totaltotal 71.7% 152 / 212 CC 30 SCAR 21.5
CC
30
Cov
73%
install_trace
20.0
trace_dump
13.0
remove_trace
12.0
CRAP 8.6
« Subs/Text.pm ↑ Summary
1 package Devel::Trace::Subs;
2 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Devel::Trace::Subs::HTML qw(html);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Devel::Trace::Subs::Text qw(text);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Symbol qw(delete_package);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our $VERSION = '0.24';
14  
15 3 our @ISA = qw(Exporter);
16 3 our @EXPORT_OK = qw(
17 trace
18 trace_dump
19 install_trace
20 remove_trace
21 );
22  
23 0 ▶$SIG{INT} = sub { 'this ensures END runs if ^C is pressed'; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
24  
25 14 ▶sub trace {
Subroutine trace: called CC=10 SCAR=23.6
Pod documented
26  
27 14 ▶ return unless $ENV{DTS_ENABLE};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"DTS_ENABLE"} 1 13 14
28  
29 13 my $flush_flow = $ENV{DTS_FLUSH_FLOW};
30  
31 13 _env();
32  
33 13 my $data = _store();
34  
35 13 my $flow_count = ++$ENV{DTS_FLOW_COUNT};
36  
37 13 ▶ my $flow = {
Condition50%1/2
(caller 1)[3] || 'main()'
l!l
013
MC/DC0%0/1
(caller 1)[3] || 'main()'
(caller 1)[3]
Truth table50%1/2
A
A= (caller 1)[3]
Aresult
11
00
38 name => $flow_count,
39 value => (caller(1))[3] || 'main()'
40 };
41  
42 13 push @{$data->{flow}}, $flow;
43  
44 13 ▶ push @{$data->{stack}}, {
Condition50%5/10
(caller 1)[3] || '-'
l!l
013
(caller 1)[0] || '-'
l!l
013
(caller 2)[3] || '-'
l!l
013
(caller 1)[1] || '-'
l!l
013
(caller 1)[2] || '-'
l!l
013
MC/DC0%0/1
(caller 1)[3] || '-'
(caller 1)[3]
MC/DC0%0/1
(caller 1)[0] || '-'
(caller 1)[0]
MC/DC0%0/1
(caller 2)[3] || '-'
(caller 2)[3]
MC/DC0%0/1
(caller 1)[1] || '-'
(caller 1)[1]
MC/DC0%0/1
(caller 1)[2] || '-'
(caller 1)[2]
Truth table50%1/2
A
A= (caller 1)[3]
Aresult
11
00
Truth table50%1/2
A
A= (caller 1)[0]
Aresult
11
00
Truth table50%1/2
A
A= (caller 2)[3]
Aresult
11
00
Truth table50%1/2
A
A= (caller 1)[1]
Aresult
11
00
Truth table50%1/2
A
A= (caller 1)[2]
Aresult
11
00
45 in => (caller(1))[3] || '-',
46 package => (caller(1))[0] || '-',
47 sub => (caller(2))[3] || '-',
48 filename => (caller(1))[1] || '-',
49 line => (caller(1))[2] || '-',
50 };
51  
52 13 _store($data);
53  
54 13 ▶ if ($flush_flow){
Branch: 1 branch
BranchTrueFalseTotal
if ($flush_flow) 1 12 13
55 1 print "\n** $flow->{name} :: $flow->{value} **\n";
56 }
57  
58 13 ▶ if (defined wantarray){
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 1 12 13
59 1 return $data;
60 }
61 }
62 11 ▶sub trace_dump {
Subroutine trace_dump: called CC=13 SCAR=25.6
Pod documented
63  
64 11 ▶ if (! $ENV{DTS_PID}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"DTS_PID"}) 1 10 11
65 1 die "\nCan't call trace_dump() without calling trace()\n\n" .
66 'Make sure to set $ENV{DTS_ENABLE} = 1;' . "\n\n";
67 }
68  
69 10 my %p = @_;
70  
71 10 my $want = $p{want};
72 10 my $out_type = $p{type};
73 10 my $file = $p{file};
74  
75 10 my $data = _store();
76  
77 10 ▶ if ($want && $want eq 'stack'){
Branch: 1 branch
BranchTrueFalseTotal
if ($want and $want eq "stack") 3 7 10
Condition100%3/3
$want and $want eq "stack"
!ll&&!rl&&r
433
MC/DC100%2/2
$want and $want eq "stack"
$want $want eq "stack"
Truth table100%3/3
A and B
A= $wantB= $want eq "stack"
ABresult
0X0
100
111
78 3 ▶ if ($out_type && $out_type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out_type and $out_type eq 'html') { } 1 2 3
Condition100%3/3
$out_type and $out_type eq "html"
!ll&&!rl&&r
111
MC/DC100%2/2
$out_type and $out_type eq "html"
$out_type $out_type eq "html"
Truth table100%3/3
A and B
A= $out_typeB= $out_type eq "html"
ABresult
0X0
100
111
79 html(
80 file => $file,
81 want => $want,
82 data => $data->{stack}
83 1 );
84 }
85 else {
86 text(
87 want => 'stack',
88 data => $data->{stack},
89 2 file => $file
90 );
91 }
92 }
93 10 ▶ if ($want && $want eq 'flow'){
Branch: 1 branch
BranchTrueFalseTotal
if ($want and $want eq "flow") 3 7 10
Condition100%3/3
$want and $want eq "flow"
!ll&&!rl&&r
433
MC/DC100%2/2
$want and $want eq "flow"
$want $want eq "flow"
Truth table100%3/3
A and B
A= $wantB= $want eq "flow"
ABresult
0X0
100
111
94 3 ▶ if ($out_type && $out_type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out_type and $out_type eq 'html') { } 1 2 3
Condition100%3/3
$out_type and $out_type eq "html"
!ll&&!rl&&r
111
MC/DC100%2/2
$out_type and $out_type eq "html"
$out_type $out_type eq "html"
Truth table100%3/3
A and B
A= $out_typeB= $out_type eq "html"
ABresult
0X0
100
111
95 html(
96 file => $file,
97 want => $want,
98 data => $data->{flow}
99 1 );
100 }
101 else {
102 text(
103 want => 'flow',
104 data => $data->{flow},
105 2 file => $file
106 );
107 }
108 }
109 10 ▶ if (! $want){
Branch: 1 branch
BranchTrueFalseTotal
if (not $want) 4 6 10
110 4 ▶ if ($out_type && $out_type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out_type and $out_type eq 'html') { } 1 3 4
Condition100%3/3
$out_type and $out_type eq "html"
!ll&&!rl&&r
211
MC/DC100%2/2
$out_type and $out_type eq "html"
$out_type $out_type eq "html"
Truth table100%3/3
A and B
A= $out_typeB= $out_type eq "html"
ABresult
0X0
100
111
111 1 html(
112 file => $file,
113 data => $data
114 );
115 }
116 else {
117 text(
118 data => {
119 flow => $data->{flow},
120 stack => $data->{stack}
121 },
122 3 file => $file
123 );
124 }
125 }
126 }
127 0 ▶sub install_trace {
Subroutine install_trace: not called CC=4 SCAR=30.0
Pod documented
128  
129 0 eval {
130 0 require Devel::Examine::Subs;
131 0 Devel::Examine::Subs->import();
132 };
133  
134 0 ▶ $@ = 1 if $ENV{EVAL_TEST}; # for test coverage
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"EVAL_TEST"} 0 0 0
135  
136 0 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
137 0 die "Devel::Examine::Subs isn't installed. Can't run install_trace(): $@";
138 }
139  
140 0 my %p = @_;
141  
142 0 my $file = $p{file};
143 0 my $extensions = $p{extensions};
144 0 my $inject = $p{inject};
145  
146 0 my $des_use = Devel::Examine::Subs->new(file => $file,);
147  
148 0 remove_trace(file => $file);
149  
150 # this is a DES pre_proc
151  
152 0 $des_use->inject(inject_use => _inject_use());
153  
154 0 my $des = Devel::Examine::Subs->new(
155 file => $file,
156 extensions => $extensions,
157 );
158  
159 0 ▶ $inject = $p{inject} || _inject_code();
Condition0%0/3
$p{'inject'} || _inject_code()
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{'inject'} || _inject_code()
$p{'inject'} _inject_code()
Truth table0%0/3
A || B
A= $p{'inject'}B= _inject_code()
ABresult
1X1
011
000
160  
161 0 $des->inject(
162 inject_after_sub_def => $inject,
163 );
164
165 }
166 0 ▶sub remove_trace {
Subroutine remove_trace: not called CC=3 SCAR=24.8
Pod documented
167
168 0 eval {
169 0 require Devel::Examine::Subs;
170 0 Devel::Examine::Subs->import();
171 };
172  
173 0 ▶ $@ = 1 if $ENV{EVAL_TEST}; # for test coverage
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"EVAL_TEST"} 0 0 0
174  
175 0 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
176 0 die "Devel::Examine::Subs isn't installed. Can't run remove_trace(): $@";
177 }
178
179 0 my %p = @_;
180 0 my $file = $p{file};
181  
182 0 my $des = Devel::Examine::Subs->new( file => $file );
183  
184 0 $des->remove(delete => [qr/injected by Devel::Trace::Subs/]);
185 }
186 0 ▶sub _inject_code {
Subroutine _inject_code: not called CC=1 SCAR=6.9
187 return [
188 0 'trace() if $ENV{DTS_ENABLE}; # injected by Devel::Trace::Subs',
189 ];
190 }
191 0 ▶sub _inject_use {
Subroutine _inject_use: not called CC=1 SCAR=6.9
192 return [
193 0 'use Devel::Trace::Subs qw(trace trace_dump); ' .
194 '# injected by Devel::Trace::Subs',
195 ];
196 }
197 13 ▶sub _env {
Subroutine _env: called CC=1 SCAR=0.0
198  
199 13 my $pid = $$;
200 13 $ENV{DTS_PID} = $pid;
201  
202 13 return $pid;
203 }
204 38 ▶sub _store {
Subroutine _store: called CC=3 SCAR=11.0
205  
206 38 my ($data) = @_;
207  
208 38 my $store = "DTS_" . join('_', ($$ x 3)) . ".dat";
209  
210 38 $ENV{DTS_STORE} = $store;
211  
212 38 my $struct;
213  
214 38 ▶ if (-f $store){
Branch: 1 branch
BranchTrueFalseTotal
if (-f $store) { } 34 4 38
215 34 $struct = retrieve($store);
216 }
217 else {
218 4 $struct = {};
219 }
220  
221 38 ▶ return $struct if ! $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 24 14 38
222  
223 14 store($data, $store);
224  
225 }
226 0 ▶sub _fold_placeholder {};
Subroutine _fold_placeholder: not called CC=1 SCAR=0.0
227  
228 3 ▶END {
Subroutine END: called CC=2 SCAR=6.9
229 3 ▶ unlink $ENV{DTS_STORE} if $ENV{DTS_STORE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DTS_STORE"} 2 1 3
230 }
231  
232 __END__
« Subs/Text.pm ↑ Summary