Subs/Postprocessor.pm

filter: Statementstmt 99.0% 106 / 107 Branchbran 85.7% 36 / 42 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 20 / 20 Podpod 66.6% 4 / 6 totaltotal 95.2% 181 / 190 CC 32 SCAR 15.2
CC
32
Cov
96%
__ANON__
11.0
__ANON__
6.0
__ANON__
4.0
CRAP 4.6
« Subs/Preprocessor.pm ↑ Summary Subs/Sub.pm »
1 package Devel::Examine::Subs::Postprocessor;
2 60 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 60 our $VERSION = '1.74';
7  
8 60 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 60 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.4
11  
12 # we need to do some trickery for Devel::Trace::Subs due to circular
13 # referencing, which broke CPAN installs. DTS does nothing if not presented,
14 # per this code
15  
16 60 eval {
17 60 require Devel::Trace::Subs;
18 0 import Devel::Trace::Subs qw(trace);
19 };
20  
21 60 ▶ if (! defined &trace){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined &Devel::Examine::Subs::Postprocessor::trace) 60 0 60
22 60 ▶ *trace = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
23 }
24 }
25  
26 132 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
27 132 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 5 127 132
28 131 my $self = {};
29 131 bless $self, shift;
30 131 $self->{post_procs} = $self->_dt();
31 131 return $self;
32 }
33 135 ▶sub _dt {
Subroutine _dt: called CC=2 SCAR=6.9
34
35 135 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 7 128 135
36  
37 134 my $dt = {
38 file_lines_contain => \&file_lines_contain,
39 subs => \&subs,
40 objects => \&objects,
41 _default => \&_default,
42 _test => \&_test,
43 _test_bad => \&_test_bad,
44 end_of_last_sub => \&end_of_last_sub,
45 };
46  
47 134 return $dt;
48 }
49 128 ▶sub exists {
Subroutine exists: called CC=3 SCAR=11.0
Pod documented
50
51 128 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 3 125 128
52  
53 127 my $self = shift;
54 127 my $string = shift;
55  
56 127 ▶ if (exists $self->{post_procs}{$string}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'post_procs'}{$string}) { } 123 4 127
57 123 return 1;
58 }
59 else {
60 4 return 0;
61 }
62 }
63 46 ▶sub subs {
Subroutine subs: called CC=2 SCAR=6.9
Pod documented
64
65 46 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 2 44 46
66
67 43 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
68
69 43 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 0 43 43
70  
71 43 my ($p, $struct) = @_;
72  
73 43 my $s = $struct;
74 43 my @subs;
75  
76 43 for my $f (keys %$s){
77  
78 42 for my $sub (keys %{$s->{$f}{subs}}){
79 354 $s->{$f}{subs}{$sub}{start}++;
80 354 $s->{$f}{subs}{$sub}{end}++;
81 354 $s->{$f}{subs}{$sub}{name} = $sub;
82 354 @{ $s->{$f}{subs}{$sub}{code} }
83 354 = @{ $s->{$f}{subs}{$sub}{code} };
84 354 push @subs, $s->{$f}{subs}{$sub};
85 }
86 }
87 43 return \@subs;
88 45 };
89 }
90 59 ▶sub file_lines_contain {
Subroutine file_lines_contain: called CC=2 SCAR=6.9
Pod documented
91
92 59 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 3 56 59
93  
94 57 ▶ return sub {
Subroutine __ANON__: called CC=11 SCAR=24.0
95
96 57 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 1 56 57
97  
98 57 my $p = shift;
99 57 my $struct = shift;
100  
101 57 my $search = $p->{search};
102  
103 57 ▶ if ($search && ! $p->{regex}){
Branch: 1 branch
BranchTrueFalseTotal
if ($search and not $p->{"regex"}) 4 53 57
Condition100%3/3
$search and not $p->{"regex"}
!ll&&!rl&&r
24294
MC/DC100%2/2
$search and not $p->{"regex"}
$search not $p->{"regex"}
Truth table100%3/3
A and not(B)
A= $searchB= not $p->{"regex"}
ABresult
0X0
100
111
104 4 $search = "\Q$search";
105 }
106  
107 57 my $s = $struct;
108  
109 57 ▶ if (not $search){
Branch: 1 branch
BranchTrueFalseTotal
unless ($search) 24 33 57
110 24 return $struct;
111 }
112  
113 33 for my $f (keys %$s){
114 33 for my $sub (keys %{$s->{$f}{subs}}){
115 297 my $found = 0;
116 297 my @has;
117 297 for (@{$s->{$f}{subs}{$sub}{code}}){
118 1553 ▶ if ($_ and /$search/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ and /$search/) 126 1427 1553
Condition100%3/3
$_ and /$search/
!ll&&!rl&&r
971330126
MC/DC100%2/2
$_ and /$search/
$_ /$search/
Truth table100%3/3
A and B
A= $_B= /$search/
ABresult
0X0
100
111
119 126 $found++;
120 126 push @has, $_;
121 }
122 }
123 297 ▶ if (! $found){
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 182 115 297
124 182 delete $s->{$f}{subs}{$sub};
125 182 next;
126 }
127 115 $s->{$f}{subs}{$sub}{code} = \@has;
128 }
129 }
130 33 return $struct;
131 58 };
132 }
133 6 ▶sub end_of_last_sub {
Subroutine end_of_last_sub: called CC=2 SCAR=6.9
Pod documented
134
135 6 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 2 4 6
136
137 4 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
138
139 4 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 0 4 4
140
141 4 my $p = shift;
142 4 my $struct = shift;
143  
144 4 my @last_line_nums;
145  
146 4 for my $sub (@$struct){
147 43 push @last_line_nums, $sub->{end};
148 }
149  
150 4 @last_line_nums = sort {$a<=>$b} @last_line_nums;
151  
152 4 return $last_line_nums[-1];
153  
154 5 };
155 }
156 4 ▶sub _test {
Subroutine _test: called CC=2 SCAR=7.0
157
158 4 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 2 2 4
159  
160 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
161 1 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 0 1 1
162 1 my ($p, $struct) = @_;
163 1 return $struct;
164 3 };
165 }
166 18 ▶sub objects {
Subroutine objects: called CC=2 SCAR=6.9
Pod undocumented
167
168 18 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 2 16 18
169  
170 # uses 'subs' post_proc
171  
172 16 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
173
174 16 ▶ trace() if $ENV{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TRACE"} 0 16 16
175  
176 16 my $p = shift;
177 16 my $struct = shift;
178  
179 16 my @return;
180  
181 16 ▶ return if not ref($struct) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $struct eq "ARRAY" 0 16 16
182  
183 16 my $search = $p->{search};
184  
185 16 ▶ if ($search && ! $p->{regex}){
Branch: 1 branch
BranchTrueFalseTotal
if ($search and not $p->{"regex"}) 1 15 16
Condition100%3/3
$search and not $p->{"regex"}
!ll&&!rl&&r
781
MC/DC100%2/2
$search and not $p->{"regex"}
$search not $p->{"regex"}
Truth table100%3/3
A and not(B)
A= $searchB= not $p->{"regex"}
ABresult
0X0
100
111
186 1 $search = "\Q$search";
187 }
188  
189 16 my $des_sub;
190  
191 16 for my $sub (@$struct){
192  
193 $des_sub
194 91 = Devel::Examine::Subs::Sub->new($sub, $sub->{name});
195  
196 91 push @return, $des_sub;
197 }
198  
199 16 return \@return;
200 17 };
201 }
202 1 ▶sub _vim_placeholder {1;}
Subroutine _vim_placeholder: called CC=1 SCAR=0.0
203 60 1;
204 __END__
« Subs/Preprocessor.pm ↑ Summary Subs/Sub.pm »