blib/lib/Devel/XSCover/Flow.pm

filter: Statementstmt 100% 277 / 277 Branchbran 97.5% 119 / 122 Conditioncond 95.0% 95 / 100 MC/DCmcdc 89.8% 53 / 59 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 97.5% 565 / 579 CC 135 SCAR 30.4
CC
135
Cov
98%
_llvm_files
33.0
_arms
30.0
clean
19.0
CRAP 20.9
« blib/lib/Devel/Cover/Report/XSCover.pm ↑ Summary blib/lib/Devel/XSCover/DB.pm »
1 package Devel::XSCover::Flow;
2  
3 55 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 55 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 55 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 55 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 55 our $VERSION = '0.10';
10  
11 55 our ($DECISION, $DIRECTIVE);
12  
13 55 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 $DECISION = qr/\b(?:if|while|for|switch)\s*\(/;
15 55 $DIRECTIVE = qr/^\s*#\s*(?:if|ifdef|ifndef|elif|else|endif|define|undef|include|line|pragma|error|warning)\b/;
16 }
17  
18 96 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
19 96 my ($class, %args) = @_;
20 96 my $self = bless {
21 dir => '.',
22 silent => 0,
23 }, $class;
24 96 $self->{$_} = $args{$_} for keys %args;
25 96 return $self;
26 }
27  
28 12 ▶sub parse_llvm {
Subroutine parse_llvm: called CC=15 SCAR=27.1
Pod documented
29 12 my ($self, $text, $files, $xsubs) = @_;
30 12 my (@functions, $fn, $block);
31 12 for my $line (split /\n/, $text) {
32 4191 ▶ if ($line =~ /^===== (.*) \((\d+)\) @ (.*):(\d+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^===== (.*) \((\d+)\) @ (.*):(\d+)\s*$/u) 97 4094 4191
33 97 $fn = { name => $1, ident => $2, file => $3, line => $4, blocks => {} };
34 97 push @functions, $fn;
35 97 $block = undef;
36 97 next;
37 }
38 4094 ▶ next unless $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless $fn 1 4093 4094
39 4093 ▶ if ($line =~ /^Block : (\d+) Counter : (\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Block : (\d+) Counter : (\d+)/u) 1044 3049 4093
40 1044 $block = $fn->{blocks}{$1} = { id => $1, count => $2, succ => [], lines => {} };
41 1044 next;
42 }
43 3049 ▶ next unless $block;
Branch: 1 branch
BranchTrueFalseTotal
unless $block 1 3048 3049
44 3048 ▶ if ($line =~ /^\s*Destination Edges : (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*Destination Edges : (.*)/u) 1044 2004 3048
45 1044 my $edges = $1;
46 1044 ▶ push @{ $block->{succ} }, [ $1, $2 ] while $edges =~ /\*?(\d+) \((\d+)\)/g;
Branch: 1 branch
BranchTrueFalseTotal
$edges =~ /\*?(\d+) \((\d+)\)/gu and do { push @{$$block{"succ"};}, [$1, $2] } 1270 1044 2314
47 1044 next;
48 }
49 2004 ▶ if ($line =~ /^\s*File: (\d+): (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*File: (\d+): (.*)/u) 965 1039 2004
50 965 push @{ $block->{lines}{$1} }, grep { length } split /,/, $2;
51 965 next;
52 }
53 }
54 12 my %name = $self->_llvm_files(\@functions, $files, $xsubs);
55 12 my %flow = (complete => 1, files => {});
56 12 for my $f (@functions) {
57 97 for my $b (values %{ $f->{blocks} }) {
58 1044 my $key = "$f->{ident}:$b->{id}";
59 1044 my @arcs = map { [ $key, "$f->{ident}:$_->[0]", $_->[1] ] } @{ $b->{succ} };
60 1044 for my $index (keys %{ $b->{lines} }) {
61 925 ▶ my $file = $name{$index} // next;
Condition100%2/2
$name{$index} // (next)
l!l
9178
MC/DC100%1/1
$name{$index} // (next)
$name{$index}
Truth table100%2/2
A
A= $name{$index}
Aresult
11
00
62 917 for my $n (@{ $b->{lines}{$index} }) {
63 1348 ▶ my $l = $flow{files}{$file}{$n} //= { blocks => {}, arcs => [], count => undef };
Condition100%2/2
$flow{"files"}{$file}{$n} //= {"blocks", {}, "arcs", [], "count", undef}
l!l
425923
MC/DC100%1/1
$flow{"files"}{$file}{$n} //= {"blocks", {}, "arcs", [], "count", undef}
$flow{"files"}{$file}{$n}
Truth table100%2/2
A
A= $flow{"files"}{$file}{$n}
Aresult
11
00
64 1348 $l->{blocks}{$key} = 1;
65 1348 push @{ $l->{arcs} }, @arcs;
66 }
67 }
68 }
69 }
70 12 return \%flow;
71 }
72  
73 12 ▶sub _llvm_files {
Subroutine _llvm_files: called CC=33 SCAR=35.0
74 12 my ($self, $functions, $files, $xsubs) = @_;
75 12 my (%name, %lines, %own, %score);
76 12 for my $f (@$functions) {
77 97 for my $b (values %{ $f->{blocks} }) {
78 1044 for my $index (keys %{ $b->{lines} }) {
79 925 $lines{$index}{$_} = 1 for @{ $b->{lines}{$index} };
80 925 ▶ $own{ $f->{ident} }{$index} = 1 if grep { $_ == $f->{line} } @{ $b->{lines}{$index} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $f->{"line"};} @{$$b{"lines"}{$index};} 98 827 925
81 }
82 }
83 }
84 12 for my $index (keys %lines) {
85 46 ▶ for my $file (keys %{ $files || {} }) {
Condition100%2/2
$files || {}
l!l
406
MC/DC100%1/1
$files || {}
$files
Truth table100%2/2
A
A= $files
Aresult
11
00
86 218 ▶ my $have = $files->{$file}{lines} || {};
Condition100%2/2
$files->{$file}{'lines'} || {}
l!l
2126
MC/DC100%1/1
$files->{$file}{'lines'} || {}
$files->{$file}{'lines'}
Truth table100%2/2
A
A= $files->{$file}{'lines'}
Aresult
11
00
87 218 my $both = grep { $have->{$_} } keys %{ $lines{$index} };
88 218 ▶ next unless $both;
Branch: 1 branch
BranchTrueFalseTotal
unless $both 140 78 218
89 78 $score{$index}{$file} = $both / (keys(%{ $lines{$index} }) + keys(%$have) - $both);
90 }
91 }
92 12 for my $f (@$functions) {
93 97 ▶ for my $index (sort { $a <=> $b } keys %{ $own{ $f->{ident} } || {} }) {
Condition50%1/2
$own{$f->{'ident'}} || {}
l!l
970
MC/DC0%0/1
$own{$f->{'ident'}} || {}
$own{$f->{'ident'}}
Truth table50%1/2
A
A= $own{$f->{'ident'}}
Aresult
11
00
94 98 ▶ next if defined $name{$index};
Branch: 1 branch
BranchTrueFalseTotal
if defined $name{$index} 60 38 98
95 38 ▶ if (my $sc = $score{$index}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sc = $score{$index}) 31 7 38
96 31 ▶ my $s = $sc->{ $f->{file} } // 0;
Condition100%2/2
$$sc{$f->{"file"}} // 0
l!l
292
MC/DC100%1/1
$$sc{$f->{"file"}} // 0
$$sc{$f->{"file"}}
Truth table100%2/2
A
A= $$sc{$f->{"file"}}
Aresult
11
00
97 31 my ($top) = sort { $sc->{$b} <=> $sc->{$a} } keys %$sc;
98 31 ▶ next unless $s >= 0.5 || $top eq $f->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless $s >= "0.5" or $top eq $f->{"file"} 3 28 31
Condition66%2/3
$s >= "0.5" or $top eq $f->{"file"}
l!l&&r!l&&!r
2803
MC/DC50%1/2
$s >= "0.5" or $top eq $f->{"file"}
$s >= "0.5" $top eq $f->{"file"}
Truth table66%2/3
A or B
A= $s >= "0.5"B= $top eq $f->{"file"}
ABresult
1X1
011
000
99 }
100 35 $name{$index} = $f->{file};
101 }
102 }
103 12 for my $f (@$functions) {
104 97 ▶ my $body = $xsubs && $xsubs->{ $f->{name} } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $body = $xsubs && $$xsubs{$f->{"name"}} or next 2 95 97
Condition100%3/3
$xsubs && $$xsubs{$f->{'name'}}
!ll&&!rl&&r
8692
MC/DC100%2/2
$xsubs && $$xsubs{$f->{'name'}}
$xsubs $$xsubs{$f->{'name'}}
Truth table100%3/3
A && B
A= $xsubsB= $$xsubs{$f->{'name'}}
ABresult
0X0
100
111
105 2 for my $b (values %{ $f->{blocks} }) {
106 2 for my $index (keys %{ $b->{lines} }) {
107 4 ▶ $name{$index} = $body if !defined $name{$index} && !$own{ $f->{ident} }{$index};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name{$index} or $own{$f->{"ident"}}{$index} 2 2 4
Condition66%2/3
defined $name{$index} or $own{$f->{"ident"}}{$index}
l!l&&r!l&&!r
202
MC/DC50%1/2
defined $name{$index} or $own{$f->{"ident"}}{$index}
defined $name{$index} $own{$f->{"ident"}}{$index}
Truth table66%2/3
A or B
A= defined $name{$index}B= $own{$f->{"ident"}}{$index}
ABresult
1X1
011
000
108 }
109 }
110 }
111 12 my %taken = map { $_ => 1 } values %name;
112 12 for my $index (sort { $a <=> $b } keys %lines) {
113 46 ▶ next if defined $name{$index};
Branch: 1 branch
BranchTrueFalseTotal
if defined $name{$index} 37 9 46
114 9 my ($best, $score) = (undef, 0);
115 9 ▶ for my $file (sort keys %{ $score{$index} || {} }) {
Condition100%2/2
$score{$index} || {}
l!l
81
MC/DC100%1/1
$score{$index} || {}
$score{$index}
Truth table100%2/2
A
A= $score{$index}
Aresult
11
00
116 17 ▶ next if $taken{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $taken{$file} 7 10 17
117 10 my $s = $score{$index}{$file};
118 10 ▶ ($best, $score) = ($file, $s) if $s > $score;
Branch: 1 branch
BranchTrueFalseTotal
if $s > $score 8 2 10
119 }
120 9 ▶ next unless defined $best;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $best 2 7 9
121 7 $name{$index} = $best;
122 7 $taken{$best} = 1;
123 }
124 12 return %name;
125 }
126  
127 8 ▶sub parse_gcc {
Subroutine parse_gcc: called CC=14 SCAR=26.4
Pod documented
128 8 my ($self, $json) = @_;
129 8 require JSON::PP;
130 8 my $data = JSON::PP->new->decode($json);
131 8 my %flow = (complete => 0, files => {});
132 8 ▶ for my $f (@{ $data->{files} || [] }) {
Condition100%2/2
$data->{'files'} || []
l!l
71
MC/DC100%1/1
$data->{'files'} || []
$data->{'files'}
Truth table100%2/2
A
A= $data->{'files'}
Aresult
11
00
133 34 my $file = $f->{file};
134 34 ▶ for my $l (@{ $f->{lines} || [] }) {
Condition100%2/2
$f->{'lines'} || []
l!l
331
MC/DC100%1/1
$f->{'lines'} || []
$f->{'lines'}
Truth table100%2/2
A
A= $f->{'lines'}
Aresult
11
00
135 707 my $n = $l->{line_number};
136 707 ▶ my $entry = $flow{files}{$file}{$n} //= { blocks => {}, arcs => [], count => undef };
Condition100%2/2
$flow{"files"}{$file}{$n} //= {"blocks", {}, "arcs", [], "count", undef}
l!l
1706
MC/DC100%1/1
$flow{"files"}{$file}{$n} //= {"blocks", {}, "arcs", [], "count", undef}
$flow{"files"}{$file}{$n}
Truth table100%2/2
A
A= $flow{"files"}{$file}{$n}
Aresult
11
00
137 707 ▶ $entry->{count} = $l->{count} if defined $l->{count};
Branch: 1 branch
BranchTrueFalseTotal
if defined $l->{"count"} 706 1 707
138 707 ▶ $entry->{blocks}{$_} = 1 for @{ $l->{block_ids} || [] };
Condition100%2/2
$l->{'block_ids'} || []
l!l
538169
MC/DC100%1/1
$l->{'block_ids'} || []
$l->{'block_ids'}
Truth table100%2/2
A
A= $l->{'block_ids'}
Aresult
11
00
139 707 ▶ for my $b (@{ $l->{branches} || [] }) {
Condition100%2/2
$l->{'branches'} || []
l!l
7061
MC/DC100%1/1
$l->{'branches'} || []
$l->{'branches'}
Truth table100%2/2
A
A= $l->{'branches'}
Aresult
11
00
140 470 ▶ next unless defined $b->{source_block_id} && defined $b->{destination_block_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b->{"source_block_id"} and defined $b->{"destination_block_id"} 115 355 470
Condition100%3/3
defined $b->{"source_block_id"} and defined $b->{"destination_block_id"}
!ll&&!rl&&r
1141355
MC/DC100%2/2
defined $b->{"source_block_id"} and defined $b->{"destination_block_id"}
defined $b->{"source_block_id"} defined $b->{"destination_block_id"}
Truth table100%3/3
A and B
A= defined $b->{"source_block_id"}B= defined $b->{"destination_block_id"}
ABresult
0X0
100
111
141 355 ▶ push @{ $entry->{arcs} }, [ $b->{source_block_id}, $b->{destination_block_id}, $b->{count} || 0 ];
Condition100%2/2
$b->{'count'} || 0
l!l
171184
MC/DC100%1/1
$b->{'count'} || 0
$b->{'count'}
Truth table100%2/2
A
A= $b->{'count'}
Aresult
11
00
142 }
143 }
144 }
145 8 return \%flow;
146 }
147  
148 23 ▶sub decisions {
Subroutine decisions: called CC=10 SCAR=23.0
Pod documented
149 23 my ($self, $flow, $inverse) = @_;
150 23 my %out;
151 23 for my $file (sort keys %{ $flow->{files} }) {
152 45 my $lines = $flow->{files}{$file};
153 45 ▶ my $path = File::Spec->file_name_is_absolute($file) ? $file : File::Spec->catfile($self->{dir}, $file);
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($file) ? : 8 37 45
154 45 ▶ open my $fh, '<', $path or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or next 36 9 45
155 36 my @src = <$fh>;
156 36 close $fh;
157 36 ▶ if (my $to = $inverse && $inverse->{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to = $inverse && $inverse->{$file}) 1 35 36
Condition100%3/3
$inverse && $inverse->{$file}
!ll&&!rl&&r
2871
MC/DC100%2/2
$inverse && $inverse->{$file}
$inverse $inverse->{$file}
Truth table100%3/3
A && B
A= $inverseB= $inverse->{$file}
ABresult
0X0
100
111
158 1 ▶ @src = map { $src[ ($to->{$_} // $_) - 1 ] // "\n" } 1 .. @src;
Condition60%3/5
$src[($to->{$_} // $_) - 1] // "\n"
l!l
100
$to->{$_} // $_
l!l&&r!l&&!r
280
MC/DC0%0/1
$src[($to->{$_} // $_) - 1] // "\n"
$src[($to->{$_} // $_) - 1]
MC/DC0%0/2
$to->{$_} // $_
$to->{$_} $_
Truth table50%1/2
A
A= $src[($to->{$_} // $_) - 1]
Aresult
11
00
Truth table66%2/3
A // B
A= $to->{$_}B= $_
ABresult
1X1
011
000
159 }
160 36 my @found;
161 36 for my $r ($self->ranges(\@src)) {
162 225 my $arms = $self->_arms($flow, $lines, $r);
163 225 ▶ push @found, { line => $r->{line}, arms => $arms } if @$arms >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$arms >= 2 76 149 225
164 }
165 36 $out{$file} = \@found;
166 }
167 23 return \%out;
168 }
169  
170 225 ▶sub _arms {
Subroutine _arms: called CC=30 SCAR=34.0
171 225 my ($self, $flow, $lines, $r) = @_;
172 225 my (%member, @arcs, %seen, %succ);
173 225 for my $n ($r->{line} .. $r->{end}) {
174 236 ▶ my $l = $lines->{$n} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $l = $lines->{$n} or next 98 138 236
175 98 $member{$_} = 1 for keys %{ $l->{blocks} };
176 98 for my $a (@{ $l->{arcs} }) {
177 242 ▶ push @arcs, $a unless $seen{"$a->[0] $a->[1]"}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{"$a->[0] $a->[1]"}++ 240 2 242
178 }
179 }
180 225 ▶ return [] unless %member;
Branch: 1 branch
BranchTrueFalseTotal
unless %member 145 80 225
181 80 push @{ $succ{ $_->[0] } }, $_->[1] for @arcs;
182 80 my (%tally, %at);
183 80 my ($body, $has_body) = (0, 0);
184 80 for my $a (@arcs) {
185 240 my ($s, $d, $c) = @$a;
186 240 my $plain = @{ $succ{$s} } <= 1;
187 240 ▶ if ($member{$d}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($member{$d}) { } 48 192 240
elsif ($flow->{'complete'} and $plain) { } 4 284 288
188 48 ▶ next unless $flow->{complete} && !$plain;
Branch: 1 branch
BranchTrueFalseTotal
unless $flow->{"complete"} and not $plain 36 12 48
Condition100%3/3
$flow->{"complete"} and not $plain
!ll&&!rl&&r
32412
MC/DC100%2/2
$flow->{"complete"} and not $plain
$flow->{"complete"} not $plain
Truth table100%3/3
A and not(B)
A= $flow->{"complete"}B= not $plain
ABresult
0X0
100
111
189 12 my %seen;
190 12 ▶ while ($member{$d} && @{ $succ{$d} || [] } <= 1 && !$seen{$d}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member{$d} and @{$succ{$d} or [];} <= 1 and not $seen{$d}++) 6 11 17
Condition100%8/8
$member{$d} and @{$succ{$d} or [];} <= 1 and not $seen{$d}++
!ll&&!rl&&r
1016
$member{$d} and @{$succ{$d} or [];} <= 1
!ll&&!rl&&r
377
$succ{$d} || []
l!l
131
MC/DC100%3/3
$member{$d} and @{$succ{$d} or [];} <= 1 and not $seen{$d}++
$member{$d} @{$succ{$d} or [];} <= 1 not $seen{$d}++
MC/DC100%1/1
$succ{$d} || []
$succ{$d}
Truth table100%4/4
A and B and not(C)
A= $member{$d}B= @{$succ{$d} or [];} <= 1C= not $seen{$d}++
ABCresult
0XX0
10X0
1100
1111
Truth table100%2/2
A
A= $succ{$d}
Aresult
11
00
191 6 ▶ last unless @{ $succ{$d} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$succ{$d} or [];} 1 5 6
Condition100%2/2
$succ{$d} || []
l!l
51
MC/DC100%1/1
$succ{$d} || []
$succ{$d}
Truth table100%2/2
A
A= $succ{$d}
Aresult
11
00
192 5 $d = $succ{$d}[0];
193 }
194 12 ▶ next if $member{$d} && @{ $succ{$d} || [] } > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $member{$d} and @{$succ{$d} or [];} > 1 7 5 12
Condition100%5/5
$member{$d} and @{$succ{$d} or [];} > 1
!ll&&!rl&&r
327
$succ{$d} || []
l!l
81
MC/DC100%2/2
$member{$d} and @{$succ{$d} or [];} > 1
$member{$d} @{$succ{$d} or [];} > 1
MC/DC100%1/1
$succ{$d} || []
$succ{$d}
Truth table100%3/3
A and B
A= $member{$d}B= @{$succ{$d} or [];} > 1
ABresult
0X0
100
111
Truth table100%2/2
A
A= $succ{$d}
Aresult
11
00
195 5 ▶ if ($r->{body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"body"}) 3 2 5
196 3 $body += $c;
197 3 $has_body = 1;
198 3 next;
199 }
200 }
201 ▶ elsif ($flow->{complete} && $plain) {
Condition100%3/3
$flow->{"complete"} and $plain
!ll&&!rl&&r
96924
MC/DC100%2/2
$flow->{"complete"} and $plain
$flow->{"complete"} $plain
Truth table100%3/3
A and B
A= $flow->{"complete"}B= $plain
ABresult
0X0
100
111
202 4 next;
203 }
204 190 $tally{$d} += $c;
205 190 ($at{$d}) = $d =~ /(\d+)\z/;
206 }
207 80 my @arms = map { $tally{$_} } sort { $at{$a} <=> $at{$b} } sort keys %tally;
208 80 ▶ if ($r->{body} && !$flow->{complete}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r->{'body'} and not $flow->{'complete'}) { } 3 77 80
elsif ($has_body) { } 3 74 77
Condition100%3/3
$r->{"body"} and not $flow->{"complete"}
!ll&&!rl&&r
7433
MC/DC100%2/2
$r->{"body"} and not $flow->{"complete"}
$r->{"body"} not $flow->{"complete"}
Truth table100%3/3
A and not(B)
A= $r->{"body"}B= not $flow->{"complete"}
ABresult
0X0
100
111
209 3 my $count = $lines->{ $r->{line} }{count};
210 3 my $seen = 0;
211 3 $seen += $_ for @arms;
212 3 ▶ unshift @arms, defined $count && $count > $seen ? $count - $seen : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $count && $count > $seen ? : 1 2 3
Condition100%3/3
defined $count and $count > $seen
!ll&&!rl&&r
111
MC/DC100%2/2
defined $count and $count > $seen
defined $count $count > $seen
Truth table100%3/3
A and B
A= defined $countB= $count > $seen
ABresult
0X0
100
111
213 }
214 elsif ($has_body) {
215 3 unshift @arms, $body;
216 }
217 80 return \@arms;
218 }
219  
220 37 ▶sub dropped {
Subroutine dropped: called CC=7 SCAR=19.5
Pod documented
221 37 my ($self, $src) = @_;
222 37 my (%dropped, $in_body);
223 37 my $n = 0;
224 37 for my $text (@$src) {
225 4369 $n++;
226 4369 ▶ $in_body = 1 if !$in_body && $text =~ /^MODULE\s*=/;
Branch: 1 branch
BranchTrueFalseTotal
if not $in_body and $text =~ /^MODULE\s*=/u 36 4333 4369
Condition100%3/3
not $in_body and $text =~ /^MODULE\s*=/u
!ll&&!rl&&r
2107222636
MC/DC100%2/2
not $in_body and $text =~ /^MODULE\s*=/u
not $in_body $text =~ /^MODULE\s*=/u
Truth table100%3/3
not(A) and B
A= not $in_bodyB= $text =~ /^MODULE\s*=/u
ABresult
0X0
100
111
227 4369 ▶ next unless $in_body && $text =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
unless $in_body and $text =~ /^\s*#/u 4353 16 4369
Condition100%3/3
$in_body and $text =~ /^\s*#/u
!ll&&!rl&&r
2226212716
MC/DC100%2/2
$in_body and $text =~ /^\s*#/u
$in_body $text =~ /^\s*#/u
Truth table100%3/3
A and B
A= $in_bodyB= $text =~ /^\s*#/u
ABresult
0X0
100
111
228 16 ▶ next if $text =~ $DIRECTIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /$Devel::XSCover::Flow::DIRECTIVE/u 8 8 16
229 8 $dropped{$n} = 1;
230 }
231 37 return \%dropped;
232 }
233  
234 89 ▶sub ranges {
Subroutine ranges: called CC=13 SCAR=25.6
Pod documented
235 89 my ($self, $src) = @_;
236 89 my @clean = $self->clean($src);
237 89 my @ranges;
238 89 for my $i (0 .. $#clean) {
239 4498 my $t = $clean[$i];
240 4498 ▶ next unless $t =~ $DECISION;
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /$Devel::XSCover::Flow::DECISION/u 4169 329 4498
241 329 my $pos = $+[0] - 1;
242 329 my ($depth, $j, $rest) = (0, $i, undef);
243 329 ▶ LINE: while ($j <= $#clean) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#clean) 343 12 355
244 343 my $s = $clean[$j];
245 343 ▶ for (my $k = $j == $i ? $pos : 0; $k < length $s; $k++) {
Branch: 2 branches
BranchTrueFalseTotal
$j == $i ? : 329 14 343
if ($k < length $s) 2520 26 2546
246 2520 my $c = substr $s, $k, 1;
247 2520 ▶ if ($c eq '(') {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '(') { } 352 2168 2520
elsif ($c eq ')' and not --$depth) { } 317 3679 3996
248 352 $depth++;
249 }
250 ▶ elsif ($c eq ')' && !--$depth) {
Condition100%3/3
$c eq ")" and not --$depth
!ll&&!rl&&r
182823317
MC/DC100%2/2
$c eq ")" and not --$depth
$c eq ")" not --$depth
Truth table100%3/3
A and not(B)
A= $c eq ")"B= not --$depth
ABresult
0X0
100
111
251 317 $rest = substr $s, $k + 1;
252 317 last LINE;
253 }
254 }
255 26 $j++;
256 }
257 329 ▶ next unless defined $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rest 12 317 329
258 317 $rest =~ s/^\s+|\s+$//g;
259 317 ▶ push @ranges, { line => $i + 1, end => $j + 1, body => length $rest && $rest ne '{' && $rest ne ';' ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
length $rest && $rest ne '{' && $rest ne ';' ? : 36 281 317
Condition100%6/6
length $rest and $rest ne "{" and $rest ne ";"
!ll&&!rl&&r
2552636
length $rest and $rest ne "{"
!ll&&!rl&&r
1906562
MC/DC100%3/3
length $rest and $rest ne "{" and $rest ne ";"
length $rest $rest ne "{" $rest ne ";"
Truth table100%4/4
A and B and C
A= length $restB= $rest ne "{"C= $rest ne ";"
ABCresult
0XX0
10X0
1100
1111
260 }
261 89 return @ranges;
262 }
263  
264 142 ▶sub clean {
Subroutine clean: called CC=19 SCAR=29.5
Pod documented
265 142 my ($self, $src) = @_;
266 142 my ($comment, $directive) = (0, 0);
267 142 my @out;
268 142 for my $line (@$src) {
269 6437 my $s = $line;
270 6437 chomp $s;
271 6437 my $o = '';
272 6437 ▶ if ($directive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive) 22 6415 6437
273 22 ▶ $directive = $s =~ /\\\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\\\z/u ? : 0 22 22
274 22 push @out, '';
275 22 next;
276 }
277 6415 ▶ if (!$comment && $s =~ /^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $comment and $s =~ /^\s*#/u) 684 5731 6415
Condition100%3/3
not $comment and $s =~ /^\s*#/u
!ll&&!rl&&r
855646684
MC/DC100%2/2
not $comment and $s =~ /^\s*#/u
not $comment $s =~ /^\s*#/u
Truth table100%3/3
not(A) and B
A= not $commentB= $s =~ /^\s*#/u
ABresult
0X0
100
111
278 684 ▶ $directive = $s =~ /\\\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\\\z/u ? : 22 662 684
279 684 push @out, '';
280 684 next;
281 }
282 5731 my $i = 0;
283 5731 ▶ while ($i < length $s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 67761 5718 73479
284 67761 ▶ if ($comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment) 228 67533 67761
285 228 my $end = index $s, '*/', $i;
286 228 ▶ if ($end < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end < 0) { } 82 146 228
287 82 $i = length $s;
288 }
289 else {
290 146 $i = $end + 2;
291 146 $comment = 0;
292 }
293 228 next;
294 }
295 67533 my $c = substr $s, $i, 1;
296 67533 ▶ if ($c eq '/' && substr($s, $i + 1, 1) eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/" and substr($s, $i + 1, 1) eq "*") 146 67387 67533
Condition100%3/3
$c eq "/" and substr($s, $i + 1, 1) eq "*"
!ll&&!rl&&r
6734938146
MC/DC100%2/2
$c eq "/" and substr($s, $i + 1, 1) eq "*"
$c eq "/" substr($s, $i + 1, 1) eq "*"
Truth table100%3/3
A and B
A= $c eq "/"B= substr($s, $i + 1, 1) eq "*"
ABresult
0X0
100
111
297 146 $comment = 1;
298 146 $i += 2;
299 146 $o .= ' ';
300 146 next;
301 }
302 67387 ▶ if ($c eq '/' && substr($s, $i + 1, 1) eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/" and substr($s, $i + 1, 1) eq "/") 13 67374 67387
Condition100%3/3
$c eq "/" and substr($s, $i + 1, 1) eq "/"
!ll&&!rl&&r
673492513
MC/DC100%2/2
$c eq "/" and substr($s, $i + 1, 1) eq "/"
$c eq "/" substr($s, $i + 1, 1) eq "/"
Truth table100%3/3
A and B
A= $c eq "/"B= substr($s, $i + 1, 1) eq "/"
ABresult
0X0
100
111
303 13 last;
304 }
305 67374 ▶ if ($c eq '"' || $c eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\"" or $c eq "'") 291 67083 67374
Condition100%3/3
$c eq "\"" or $c eq "'"
l!l&&r!l&&!r
2652667083
MC/DC100%2/2
$c eq "\"" or $c eq "'"
$c eq "\"" $c eq "'"
Truth table100%3/3
A or B
A= $c eq "\""B= $c eq "'"
ABresult
1X1
011
000
306 291 my $j = $i + 1;
307 291 ▶ while ($j < length $s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < length $s) 2114 0 2114
308 2114 my $d = substr $s, $j, 1;
309 2114 ▶ $j++ if $d eq '\\';
Branch: 1 branch
BranchTrueFalseTotal
if $d eq "\\" 0 2114 2114
310 2114 $j++;
311 2114 ▶ last if $d eq $c;
Branch: 1 branch
BranchTrueFalseTotal
if $d eq $c 291 1823 2114
312 }
313 291 $o .= $c . $c;
314 291 $i = $j;
315 291 next;
316 }
317 67083 $o .= $c;
318 67083 $i++;
319 }
320 5731 push @out, $o;
321 }
322 142 return @out;
323 }
324  
325 55 1;
326  
327 __END__
« blib/lib/Devel/Cover/Report/XSCover.pm ↑ Summary blib/lib/Devel/XSCover/DB.pm »