blib/lib/Devel/XSCover/Flow.pm

filter: Statementstmt 100% 264 / 264 Branchbran 97.4% 115 / 118 Conditioncond 96.8% 91 / 94 MC/DCmcdc 92.8% 52 / 56 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 98.1% 543 / 553 CC 126 SCAR 29.2
CC
126
Cov
99%
_arms
30.0
_llvm_files
24.0
clean
19.0
CRAP 18.6
« blib/lib/Devel/XSCover/DB.pm ↑ Summary blib/lib/Devel/XSCover/Gcov.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.09';
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 11 ▶sub parse_llvm {
Subroutine parse_llvm: called CC=15 SCAR=27.1
Pod documented
29 11 my ($self, $text, $files, $xsubs) = @_;
30 11 my (@functions, $fn, $block);
31 11 for my $line (split /\n/, $text) {
32 4186 ▶ if ($line =~ /^===== (.*) \((\d+)\) @ (.*):(\d+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^===== (.*) \((\d+)\) @ (.*):(\d+)\s*$/u) 96 4090 4186
33 96 $fn = { name => $1, ident => $2, file => $3, line => $4, blocks => {} };
34 96 push @functions, $fn;
35 96 $block = undef;
36 96 next;
37 }
38 4090 ▶ next unless $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless $fn 1 4089 4090
39 4089 ▶ if ($line =~ /^Block : (\d+) Counter : (\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Block : (\d+) Counter : (\d+)/u) 1043 3046 4089
40 1043 $block = $fn->{blocks}{$1} = { id => $1, count => $2, succ => [], lines => {} };
41 1043 next;
42 }
43 3046 ▶ next unless $block;
Branch: 1 branch
BranchTrueFalseTotal
unless $block 1 3045 3046
44 3045 ▶ if ($line =~ /^\s*Destination Edges : (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*Destination Edges : (.*)/u) 1043 2002 3045
45 1043 my $edges = $1;
46 1043 ▶ 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] } 1269 1043 2312
47 1043 next;
48 }
49 2002 ▶ if ($line =~ /^\s*File: (\d+): (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*File: (\d+): (.*)/u) 963 1039 2002
50 963 push @{ $block->{lines}{$1} }, grep { length } split /,/, $2;
51 963 next;
52 }
53 }
54 11 my %name = $self->_llvm_files(\@functions, $files, $xsubs);
55 11 my %flow = (complete => 1, files => {});
56 11 for my $f (@functions) {
57 96 for my $b (values %{ $f->{blocks} }) {
58 1043 my $key = "$f->{ident}:$b->{id}";
59 1043 my @arcs = map { [ $key, "$f->{ident}:$_->[0]", $_->[1] ] } @{ $b->{succ} };
60 1043 for my $index (keys %{ $b->{lines} }) {
61 923 ▶ my $file = $name{$index} // next;
Condition100%2/2
$name{$index} // (next)
l!l
9194
MC/DC100%1/1
$name{$index} // (next)
$name{$index}
Truth table100%2/2
A
A= $name{$index}
Aresult
11
00
62 919 for my $n (@{ $b->{lines}{$index} }) {
63 1350 ▶ my $l = $flow{files}{$file}{$n} //= { blocks => {}, arcs => [], count => undef };
Condition100%2/2
$flow{"files"}{$file}{$n} //= {"blocks", {}, "arcs", [], "count", undef}
l!l
425925
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 1350 $l->{blocks}{$key} = 1;
65 1350 push @{ $l->{arcs} }, @arcs;
66 }
67 }
68 }
69 }
70 11 return \%flow;
71 }
72  
73 11 ▶sub _llvm_files {
Subroutine _llvm_files: called CC=24 SCAR=31.8
74 11 my ($self, $functions, $files, $xsubs) = @_;
75 11 my (%name, %lines, %own);
76 11 for my $f (@$functions) {
77 96 for my $b (values %{ $f->{blocks} }) {
78 1043 for my $index (keys %{ $b->{lines} }) {
79 923 $lines{$index}{$_} = 1 for @{ $b->{lines}{$index} };
80 923 ▶ $own{ $f->{ident} }{$index} = 1 if grep { $_ == $f->{line} } @{ $b->{lines}{$index} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $f->{"line"};} @{$$b{"lines"}{$index};} 96 827 923
81 923 ▶ $name{$index} = $f->{file} if !defined $name{$index} && $own{ $f->{ident} }{$index};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name{$index} and $own{$f->{"ident"}}{$index} 35 888 923
Condition100%3/3
not defined $name{$index} and $own{$f->{"ident"}}{$index}
!ll&&!rl&&r
75313535
MC/DC100%2/2
not defined $name{$index} and $own{$f->{"ident"}}{$index}
not defined $name{$index} $own{$f->{"ident"}}{$index}
Truth table100%3/3
not(A) and B
A= not defined $name{$index}B= $own{$f->{"ident"}}{$index}
ABresult
0X0
100
111
82 }
83 }
84 }
85 11 for my $f (@$functions) {
86 96 ▶ my $body = $xsubs && $xsubs->{ $f->{name} } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $body = $xsubs && $$xsubs{$f->{"name"}} or next 2 94 96
Condition100%3/3
$xsubs && $$xsubs{$f->{'name'}}
!ll&&!rl&&r
8592
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
87 2 for my $b (values %{ $f->{blocks} }) {
88 2 for my $index (keys %{ $b->{lines} }) {
89 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
90 }
91 }
92 }
93 11 my %taken = map { $_ => 1 } values %name;
94 11 for my $index (sort { $a <=> $b } keys %lines) {
95 44 ▶ next if defined $name{$index};
Branch: 1 branch
BranchTrueFalseTotal
if defined $name{$index} 37 7 44
96 7 my ($best, $score) = (undef, 0);
97 7 ▶ for my $file (sort keys %{ $files || {} }) {
Condition100%2/2
$files || {}
l!l
61
MC/DC100%1/1
$files || {}
$files
Truth table100%2/2
A
A= $files
Aresult
11
00
98 37 ▶ next if $taken{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $taken{$file} 23 14 37
99 14 ▶ my $have = $files->{$file}{lines} || {};
Condition100%2/2
$files->{$file}{'lines'} || {}
l!l
131
MC/DC100%1/1
$files->{$file}{'lines'} || {}
$files->{$file}{'lines'}
Truth table100%2/2
A
A= $files->{$file}{'lines'}
Aresult
11
00
100 14 my $both = grep { $have->{$_} } keys %{ $lines{$index} };
101 14 ▶ next unless $both;
Branch: 1 branch
BranchTrueFalseTotal
unless $both 5 9 14
102 9 my $union = keys(%{ $lines{$index} }) + keys(%$have) - $both;
103 9 my $s = $both / $union;
104 9 ▶ ($best, $score) = ($file, $s) if $s > $score;
Branch: 1 branch
BranchTrueFalseTotal
if $s > $score 7 2 9
105 }
106 7 ▶ next unless defined $best;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $best 1 6 7
107 6 $name{$index} = $best;
108 6 $taken{$best} = 1;
109 }
110 11 return %name;
111 }
112  
113 8 ▶sub parse_gcc {
Subroutine parse_gcc: called CC=14 SCAR=26.4
Pod documented
114 8 my ($self, $json) = @_;
115 8 require JSON::PP;
116 8 my $data = JSON::PP->new->decode($json);
117 8 my %flow = (complete => 0, files => {});
118 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
119 34 my $file = $f->{file};
120 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
121 707 my $n = $l->{line_number};
122 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
123 707 ▶ $entry->{count} = $l->{count} if defined $l->{count};
Branch: 1 branch
BranchTrueFalseTotal
if defined $l->{"count"} 706 1 707
124 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
125 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
126 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
127 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
128 }
129 }
130 }
131 8 return \%flow;
132 }
133  
134 23 ▶sub decisions {
Subroutine decisions: called CC=10 SCAR=23.0
Pod documented
135 23 my ($self, $flow, $inverse) = @_;
136 23 my %out;
137 23 for my $file (sort keys %{ $flow->{files} }) {
138 46 my $lines = $flow->{files}{$file};
139 46 ▶ 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 38 46
140 46 ▶ open my $fh, '<', $path or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or next 37 9 46
141 37 my @src = <$fh>;
142 37 close $fh;
143 37 ▶ if (my $to = $inverse && $inverse->{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to = $inverse && $inverse->{$file}) 1 36 37
Condition100%3/3
$inverse && $inverse->{$file}
!ll&&!rl&&r
2881
MC/DC100%2/2
$inverse && $inverse->{$file}
$inverse $inverse->{$file}
Truth table100%3/3
A && B
A= $inverseB= $inverse->{$file}
ABresult
0X0
100
111
144 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
145 }
146 37 my @found;
147 37 for my $r ($self->ranges(\@src)) {
148 226 my $arms = $self->_arms($flow, $lines, $r);
149 226 ▶ push @found, { line => $r->{line}, arms => $arms } if @$arms >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$arms >= 2 77 149 226
150 }
151 37 $out{$file} = \@found;
152 }
153 23 return \%out;
154 }
155  
156 226 ▶sub _arms {
Subroutine _arms: called CC=30 SCAR=34.0
157 226 my ($self, $flow, $lines, $r) = @_;
158 226 my (%member, @arcs, %seen, %succ);
159 226 for my $n ($r->{line} .. $r->{end}) {
160 237 ▶ my $l = $lines->{$n} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $l = $lines->{$n} or next 99 138 237
161 99 $member{$_} = 1 for keys %{ $l->{blocks} };
162 99 for my $a (@{ $l->{arcs} }) {
163 244 ▶ push @arcs, $a unless $seen{"$a->[0] $a->[1]"}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{"$a->[0] $a->[1]"}++ 242 2 244
164 }
165 }
166 226 ▶ return [] unless %member;
Branch: 1 branch
BranchTrueFalseTotal
unless %member 145 81 226
167 81 push @{ $succ{ $_->[0] } }, $_->[1] for @arcs;
168 81 my (%tally, %at);
169 81 my ($body, $has_body) = (0, 0);
170 81 for my $a (@arcs) {
171 242 my ($s, $d, $c) = @$a;
172 242 my $plain = @{ $succ{$s} } <= 1;
173 242 ▶ if ($member{$d}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($member{$d}) { } 48 194 242
elsif ($flow->{'complete'} and $plain) { } 4 286 290
174 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
175 12 my %seen;
176 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
177 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
178 5 $d = $succ{$d}[0];
179 }
180 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
181 5 ▶ if ($r->{body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"body"}) 3 2 5
182 3 $body += $c;
183 3 $has_body = 1;
184 3 next;
185 }
186 }
187 ▶ elsif ($flow->{complete} && $plain) {
Condition100%3/3
$flow->{"complete"} and $plain
!ll&&!rl&&r
96944
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
188 4 next;
189 }
190 192 $tally{$d} += $c;
191 192 ($at{$d}) = $d =~ /(\d+)\z/;
192 }
193 81 my @arms = map { $tally{$_} } sort { $at{$a} <=> $at{$b} } sort keys %tally;
194 81 ▶ if ($r->{body} && !$flow->{complete}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r->{'body'} and not $flow->{'complete'}) { } 3 78 81
elsif ($has_body) { } 3 75 78
Condition100%3/3
$r->{"body"} and not $flow->{"complete"}
!ll&&!rl&&r
7533
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
195 3 my $count = $lines->{ $r->{line} }{count};
196 3 my $seen = 0;
197 3 $seen += $_ for @arms;
198 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
199 }
200 elsif ($has_body) {
201 3 unshift @arms, $body;
202 }
203 81 return \@arms;
204 }
205  
206 37 ▶sub dropped {
Subroutine dropped: called CC=7 SCAR=19.5
Pod documented
207 37 my ($self, $src) = @_;
208 37 my (%dropped, $in_body);
209 37 my $n = 0;
210 37 for my $text (@$src) {
211 4369 $n++;
212 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
213 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
214 16 ▶ next if $text =~ $DIRECTIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /$Devel::XSCover::Flow::DIRECTIVE/u 8 8 16
215 8 $dropped{$n} = 1;
216 }
217 37 return \%dropped;
218 }
219  
220 90 ▶sub ranges {
Subroutine ranges: called CC=13 SCAR=25.6
Pod documented
221 90 my ($self, $src) = @_;
222 90 my @clean = $self->clean($src);
223 90 my @ranges;
224 90 for my $i (0 .. $#clean) {
225 4516 my $t = $clean[$i];
226 4516 ▶ next unless $t =~ $DECISION;
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /$Devel::XSCover::Flow::DECISION/u 4186 330 4516
227 330 my $pos = $+[0] - 1;
228 330 my ($depth, $j, $rest) = (0, $i, undef);
229 330 ▶ LINE: while ($j <= $#clean) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#clean) 344 12 356
230 344 my $s = $clean[$j];
231 344 ▶ for (my $k = $j == $i ? $pos : 0; $k < length $s; $k++) {
Branch: 2 branches
BranchTrueFalseTotal
$j == $i ? : 330 14 344
if ($k < length $s) 2527 26 2553
232 2527 my $c = substr $s, $k, 1;
233 2527 ▶ if ($c eq '(') {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '(') { } 353 2174 2527
elsif ($c eq ')' and not --$depth) { } 318 3689 4007
234 353 $depth++;
235 }
236 ▶ elsif ($c eq ')' && !--$depth) {
Condition100%3/3
$c eq ")" and not --$depth
!ll&&!rl&&r
183323318
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
237 318 $rest = substr $s, $k + 1;
238 318 last LINE;
239 }
240 }
241 26 $j++;
242 }
243 330 ▶ next unless defined $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rest 12 318 330
244 318 $rest =~ s/^\s+|\s+$//g;
245 318 ▶ 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 282 318
Condition100%6/6
length $rest and $rest ne "{" and $rest ne ";"
!ll&&!rl&&r
2562636
length $rest and $rest ne "{"
!ll&&!rl&&r
1916562
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
246 }
247 90 return @ranges;
248 }
249  
250 143 ▶sub clean {
Subroutine clean: called CC=19 SCAR=29.5
Pod documented
251 143 my ($self, $src) = @_;
252 143 my ($comment, $directive) = (0, 0);
253 143 my @out;
254 143 for my $line (@$src) {
255 6455 my $s = $line;
256 6455 chomp $s;
257 6455 my $o = '';
258 6455 ▶ if ($directive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive) 22 6433 6455
259 22 ▶ $directive = $s =~ /\\\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\\\z/u ? : 0 22 22
260 22 push @out, '';
261 22 next;
262 }
263 6433 ▶ if (!$comment && $s =~ /^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $comment and $s =~ /^\s*#/u) 687 5746 6433
Condition100%3/3
not $comment and $s =~ /^\s*#/u
!ll&&!rl&&r
855661687
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
264 687 ▶ $directive = $s =~ /\\\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\\\z/u ? : 22 665 687
265 687 push @out, '';
266 687 next;
267 }
268 5746 my $i = 0;
269 5746 ▶ while ($i < length $s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 67938 5733 73671
270 67938 ▶ if ($comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment) 228 67710 67938
271 228 my $end = index $s, '*/', $i;
272 228 ▶ if ($end < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end < 0) { } 82 146 228
273 82 $i = length $s;
274 }
275 else {
276 146 $i = $end + 2;
277 146 $comment = 0;
278 }
279 228 next;
280 }
281 67710 my $c = substr $s, $i, 1;
282 67710 ▶ if ($c eq '/' && substr($s, $i + 1, 1) eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/" and substr($s, $i + 1, 1) eq "*") 146 67564 67710
Condition100%3/3
$c eq "/" and substr($s, $i + 1, 1) eq "*"
!ll&&!rl&&r
6752638146
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
283 146 $comment = 1;
284 146 $i += 2;
285 146 $o .= ' ';
286 146 next;
287 }
288 67564 ▶ if ($c eq '/' && substr($s, $i + 1, 1) eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/" and substr($s, $i + 1, 1) eq "/") 13 67551 67564
Condition100%3/3
$c eq "/" and substr($s, $i + 1, 1) eq "/"
!ll&&!rl&&r
675262513
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
289 13 last;
290 }
291 67551 ▶ if ($c eq '"' || $c eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\"" or $c eq "'") 291 67260 67551
Condition100%3/3
$c eq "\"" or $c eq "'"
l!l&&r!l&&!r
2652667260
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
292 291 my $j = $i + 1;
293 291 ▶ while ($j < length $s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < length $s) 2114 0 2114
294 2114 my $d = substr $s, $j, 1;
295 2114 ▶ $j++ if $d eq '\\';
Branch: 1 branch
BranchTrueFalseTotal
if $d eq "\\" 0 2114 2114
296 2114 $j++;
297 2114 ▶ last if $d eq $c;
Branch: 1 branch
BranchTrueFalseTotal
if $d eq $c 291 1823 2114
298 }
299 291 $o .= $c . $c;
300 291 $i = $j;
301 291 next;
302 }
303 67260 $o .= $c;
304 67260 $i++;
305 }
306 5746 push @out, $o;
307 }
308 143 return @out;
309 }
310  
311 55 1;
312  
313 __END__
« blib/lib/Devel/XSCover/DB.pm ↑ Summary blib/lib/Devel/XSCover/Gcov.pm »