blib/lib/Algorithm/Merge.pm

filter: Statementstmt 98.2% 279 / 284 Branchbran 89.5% 111 / 124 Conditioncond 74.2% 49 / 66 MC/DCmcdc 59.5% 25 / 42 Subroutinesub 82.8% 29 / 35 Podpod 75.0% 3 / 4 totaltotal 89.3% 496 / 555 CC 92 SCAR 32.2
CC
92
Cov
93%
traverse_sequences3
50.3
merge
21.2
__ANON__
12.0
CRAP 25.1
↑ Summary
1 package Algorithm::Merge;
2  
3 3 ▶use Algorithm::Diff ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use vars qw(@EXPORT_OK @ISA $VERSION $REVISION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 $VERSION = '0.08';
11  
12 3 $REVISION = (qw$Revision: 1.11 $)[-1];
13  
14 3 @EXPORT_OK = qw(diff3 merge traverse_sequences3);
15  
16 3 @ISA = qw(Exporter);
17  
18 1547 ▶sub diag {
Subroutine diag: called CC=2 SCAR=7.6
Pod undocumented
19 1547 ▶ main::diag(@_) if($Algorithm::Merge::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Algorithm::Merge::DEBUG 0 1547 1547
20 }
21  
22 61 ▶sub diff3 {
Subroutine diff3: called CC=5 SCAR=16.2
Pod documented
23 61 my $pivot = shift; # array ref
24 61 my $doca = shift; # array ref
25 61 my $docb = shift; # array ref
26 61 my $keyGen = shift;
27  
28 61 my @ret;
29  
30 61 ▶ if(@$doca == 0 && @$docb == 0 && @$pivot == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$doca == 0 and @$docb == 0 and @$pivot == 0) 1 60 61
Condition100%6/6
@$doca == 0 and @$docb == 0 and @$pivot == 0
!ll&&!rl&&r
5911
@$doca == 0 and @$docb == 0
!ll&&!rl&&r
5722
MC/DC100%3/3
@$doca == 0 and @$docb == 0 and @$pivot == 0
@$doca == 0 @$docb == 0 @$pivot == 0
Truth table100%4/4
A and B and C
A= @$doca == 0B= @$docb == 0C= @$pivot == 0
ABCresult
0XX0
10X0
1100
1111
31 1 return [ [ ] ];
32 }
33  
34 60 my $no_change;
35  
36 # if($keyGen) {
37 # $no_change = sub {
38 # if($keyGen->($pivot -> [$_[0]]) ne $keyGen->($doca -> [$_[1]])
39 # || $keyGen->($pivot -> [$_[0]]) ne $keyGen->($docb -> [$_[2]])
40 # || $keyGen->($doca -> [$_[1]]) ne $keyGen->($docb -> [$_[2]]))
41 # {
42 # croak "No change detected, but elements differ between sequences. Please submit a bug report to jsmith\@cpan.org with a description of the set of sequences which lead to this error.\n";
43 # }
44 # push @ret, [ 'u', $pivot -> [$_[0]], $doca -> [$_[1]], $docb -> [$_[2]] ];
45 # };
46 # }
47 # else {
48 161 ▶ $no_change = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 # if($pivot -> [$_[0]] ne $doca -> [$_[1]]
50 # || $pivot -> [$_[0]] ne $docb -> [$_[2]]
51 # || $doca -> [$_[1]] ne $docb -> [$_[2]])
52 # {
53 # croak "No change detected, but elements differ between sequences. Please submit a bug report to jsmith\@cpan.org with a description of the set of sequences which lead to this error.\n";
54 # }
55 161 push @ret, [ 'u', $pivot -> [$_[0]], $doca -> [$_[1]], $docb -> [$_[2]] ];
56 60 };
57 # }
58  
59 31 ▶ my $conflict = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
60 31 my($a, $b, $c);
61 31 ▶ $a = $pivot -> [$_[0]] if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 23 8 31
62 31 ▶ $b = $doca -> [$_[1]] if defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 30 1 31
63 31 ▶ $c = $docb -> [$_[2]] if defined $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] 30 1 31
64 31 push @ret, [ 'c', $a, $b, $c ];
65 60 };
66  
67 46 ▶ my $diff_a = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
68 46 ▶ if(@_ == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1) { } 26 20 46
elsif (@_ == 2) { } 15 5 20
elsif (@_ == 3) { } 5 0 5
69 26 push @ret, [ 'o', $pivot -> [$_[0]], undef, undef ];
70 }
71 elsif(@_ == 2) {
72 15 push @ret, [ 'o', undef, $doca -> [$_[0]], $docb -> [$_[1]] ];
73 }
74 elsif(@_ == 3) {
75 5 push @ret, [ 'o', $pivot -> [$_[0]], $doca -> [$_[1]], $docb -> [$_[2]] ];
76 }
77 60 };
78  
79 46 ▶ my $diff_b = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
80 46 ▶ if(@_ == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1) { } 14 32 46
elsif (@_ == 2) { } 22 10 32
elsif (@_ == 3) { } 10 0 10
81 14 push @ret, [ 'l', undef, $doca -> [$_[0]], undef ];
82 }
83 elsif(@_ == 2) {
84 22 push @ret, [ 'l', $pivot -> [$_[0]], undef, $docb -> [$_[1]] ];
85 }
86 elsif(@_ == 3) {
87 10 push @ret, [ 'l', $pivot -> [$_[0]], $doca -> [$_[1]], $docb -> [$_[2]] ];
88 }
89 60 };
90  
91 46 ▶ my $diff_c = sub {
Subroutine __ANON__: called CC=10 SCAR=24.9
92 46 ▶ if(@_ == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1) { } 13 33 46
elsif (@_ == 2) { } 20 13 33
elsif (@_ == 3) { } 13 0 13
93 13 ▶ push @ret, [ 'r', undef, undef, (defined($_[0]) ? $docb -> [$_[0]] : undef) ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 13 0 13
94 }
95 elsif(@_ == 2) {
96 20 ▶ push @ret, [ 'r', (defined($_[0]) ? $pivot -> [$_[0]] : undef), (defined($_[1]) ? $doca -> [$_[1]] : undef), undef ];
Branch: 2 branches
BranchTrueFalseTotal
defined $_[0] ? : 20 0 20
defined $_[1] ? : 20 0 20
97 }
98 elsif(@_ == 3) {
99 13 ▶ push @ret, [ 'r', (defined($_[0]) ? $pivot -> [$_[0]] : undef), (defined($_[1]) ? $doca -> [$_[1]] : undef), (defined($_[0]) ? $docb -> [$_[2]] : undef)];
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 13 0 13
defined $_[1] ? : 8 5 13
defined $_[0] ? : 13 0 13
100 }
101 60 };
102  
103 60 traverse_sequences3(
104 $pivot, $doca, $docb,
105 {
106 NO_CHANGE => $no_change,
107 A_DIFF => $diff_a,
108 B_DIFF => $diff_b,
109 C_DIFF => $diff_c,
110 CONFLICT => $conflict,
111 },
112 $keyGen, @_
113 );
114  
115 60 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 60 60
116 0 return @ret;
117 }
118 else {
119 60 return \@ret;
120 }
121 }
122  
123 3 ▶use constant A => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 3 ▶use constant B => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 3 ▶use constant C => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 3 ▶use constant D => 8; # should be an undef
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 3 ▶use constant AB_A => 32;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 3 ▶use constant AB_B => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 3 ▶use constant AC_A => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 3 ▶use constant AC_C => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 3 ▶use constant BC_B => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
133 3 ▶use constant BC_C => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 3 ▶use constant CB_C => 3; # not used in calculations
Subroutine BEGIN: called CC=1 SCAR=0.0
135 3 ▶use constant CB_B => 5; # not used in calculations
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 3 my @abc_s;
138 3 $abc_s[(A|B)*8+A] = AB_A;
139 3 $abc_s[(A|B)*8+B] = AB_B;
140 3 $abc_s[(A|C)*8+A] = AC_A;
141 3 $abc_s[(A|C)*8+C] = AC_C;
142 3 $abc_s[(B|C)*8+B] = BC_B;
143 3 $abc_s[(B|C)*8+C] = BC_C;
144  
145 60 ▶sub traverse_sequences3 {
Subroutine traverse_sequences3: called CC=50 SCAR=39.2
Pod documented
146 60 my $adoc = shift; # array ref
147 60 my $bdoc = shift; # array ref
148 60 my $cdoc = shift; # array ref
149 60 ▶ my $callbacks = shift || {};
Condition50%1/2
shift() || {}
l!l
600
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
150 60 my $keyGen = shift;
151 60 ▶ my $a_diff = $callbacks->{'A_DIFF'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'A_DIFF'} || sub { }
l!l&&r!l&&!r
6000
MC/DC0%0/2
$callbacks->{'A_DIFF'} || sub { }
$callbacks->{'A_DIFF'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'A_DIFF'}B= sub { }
ABresult
1X1
011
000
152 60 ▶ my $b_diff = $callbacks->{'B_DIFF'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'B_DIFF'} || sub { }
l!l&&r!l&&!r
6000
MC/DC0%0/2
$callbacks->{'B_DIFF'} || sub { }
$callbacks->{'B_DIFF'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'B_DIFF'}B= sub { }
ABresult
1X1
011
000
153 60 ▶ my $c_diff = $callbacks->{'C_DIFF'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'C_DIFF'} || sub { }
l!l&&r!l&&!r
6000
MC/DC0%0/2
$callbacks->{'C_DIFF'} || sub { }
$callbacks->{'C_DIFF'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'C_DIFF'}B= sub { }
ABresult
1X1
011
000
154 60 ▶ my $no_change = $callbacks->{'NO_CHANGE'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'NO_CHANGE'} || sub { }
l!l&&r!l&&!r
6000
MC/DC0%0/2
$callbacks->{'NO_CHANGE'} || sub { }
$callbacks->{'NO_CHANGE'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'NO_CHANGE'}B= sub { }
ABresult
1X1
011
000
155 60 ▶ my $conflict = $callbacks->{'CONFLICT'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'CONFLICT'} || sub { }
l!l&&r!l&&!r
6000
MC/DC0%0/2
$callbacks->{'CONFLICT'} || sub { }
$callbacks->{'CONFLICT'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'CONFLICT'}B= sub { }
ABresult
1X1
011
000
156  
157 60 my $b_len = scalar(@{$bdoc});
158 60 my $c_len = scalar(@{$cdoc});
159 60 ▶ my $target_len = $b_len < $c_len ? $b_len : $c_len;
Branch: 1 branch
BranchTrueFalseTotal
$b_len < $c_len ? : 19 41 60
160 60 my $bc_different_lengths = $b_len != $c_len;
161  
162 60 my(@bdoc_save, @cdoc_save);
163  
164 # make these into traverse_sequences calls
165 60 my($left, $right);
166 60 my %diffs;
167  
168 my $ts_callbacks = {
169 384 ▶ DISCARD_A => sub { # discard left
Subroutine __ANON__: called CC=1 SCAR=0.0
170 384 push @{$diffs{$left}}, $_[0];
171 },
172 352 ▶ DISCARD_B => sub { # discard right
Subroutine __ANON__: called CC=1 SCAR=0.0
173 352 push @{$diffs{$right}}, $_[1];
174 },
175 60 };
176  
177 60 @diffs{(AB_A, AB_B)} = ([], []);
178 60 $left = AB_A; $right = AB_B;
179 60 Algorithm::Diff::traverse_sequences( $adoc, $bdoc, $ts_callbacks, $keyGen, @_);
180  
181 60 @diffs{(AC_A, AC_C)} = ([], []);
182 60 $left = AC_A; $right = AC_C;
183 60 Algorithm::Diff::traverse_sequences( $adoc, $cdoc, $ts_callbacks, $keyGen, @_);
184  
185 60 ▶ if($bc_different_lengths) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bc_different_lengths) { } 35 25 60
186
187 35 @diffs{(CB_C, CB_B)} = ([], []);
188 35 $left = CB_C; $right = CB_B;
189 35 Algorithm::Diff::traverse_sequences( $cdoc, $bdoc, $ts_callbacks, $keyGen, @_);
190  
191 35 @diffs{(BC_B, BC_C)} = ([], []);
192 35 $left = BC_B; $right = BC_C;
193 35 Algorithm::Diff::traverse_sequences( $bdoc, $cdoc, $ts_callbacks, $keyGen, @_);
194  
195 35 ▶ if(join(",", @{$diffs{&CB_B}}) ne join(",", @{$diffs{&BC_B}}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (join(",", @{$diffs{&CB_B};}) ne join(",", @{$diffs{&BC_B};}) or join(",", @{$diffs{&CB_C};}) ne join(",", @{$diffs{&BC_C};})) 4 31 35
Condition66%2/3
join(",", @{$diffs{&CB_B};}) ne join(",", @{$diffs{&BC_B};}) or join(",", @{$diffs{&CB_C};}) ne join(",", @{$diffs{&BC_C};})
l!l&&r!l&&!r
4031
MC/DC50%1/2
join(",", @{$diffs{&CB_B};}) ne join(",", @{$diffs{&BC_B};}) or join(",", @{$diffs{&CB_C};}) ne join(",", @{$diffs{&BC_C};})
join(",", @{$diffs{&CB_B};}) ne join(",", @{$diffs{&BC_B};}) join(",", @{$diffs{&CB_C};}) ne join(",", @{$diffs{&BC_C};})
Truth table66%2/3
A or B
A= join(",", @{$diffs{&CB_B};}) ne join(",", @{$diffs{&BC_B};})B= join(",", @{$diffs{&CB_C};}) ne join(",", @{$diffs{&BC_C};})
ABresult
1X1
011
000
196 31 join(",", @{$diffs{&CB_C}}) ne join(",", @{$diffs{&BC_C}}))
197 {
198 4 @bdoc_save = splice @{$bdoc}, $target_len;
199 4 @cdoc_save = splice @{$cdoc}, $target_len;
200
201 4 carp "Algorithm::Diff::diff is not symmetric for second and third sequences - results might not be correct";
202 }
203  
204 35 @diffs{(BC_B, BC_C)} = ([], []);
205 35 $left = BC_B; $right = BC_C;
206 35 Algorithm::Diff::traverse_sequences( $bdoc, $cdoc, $ts_callbacks, $keyGen, @_);
207  
208 35 ▶ if(scalar(@bdoc_save) || scalar(@cdoc_save)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @bdoc_save or scalar @cdoc_save) 4 31 35
Condition100%2/2
scalar @bdoc_save or scalar @cdoc_save
l!l
233
MC/DC100%1/1
scalar @bdoc_save or scalar @cdoc_save
scalar @bdoc_save
Truth table100%2/2
A
A= scalar @bdoc_save
Aresult
11
00
209 4 ▶ push @{$diffs{&BC_B}}, ($target_len .. $b_len) if $target_len < $b_len;
Branch: 1 branch
BranchTrueFalseTotal
if $target_len < $b_len 2 2 4
210 4 ▶ push @{$diffs{&BC_C}}, ($target_len .. $c_len) if $target_len < $c_len;
Branch: 1 branch
BranchTrueFalseTotal
if $target_len < $c_len 2 2 4
211
212 4 push @{$bdoc}, @bdoc_save; undef @bdoc_save;
213 4 push @{$cdoc}, @cdoc_save; undef @cdoc_save;
214 }
215 }
216 else {
217 25 @diffs{(BC_B, BC_C)} = ([], []);
218 25 $left = BC_B; $right = BC_C;
219 25 Algorithm::Diff::traverse_sequences( $bdoc, $cdoc, $ts_callbacks, $keyGen, @_);
220 }
221  
222 60 my @pos;
223 60 @pos[A, B, C] = (0, 0, 0);
224  
225 60 my @sizes;
226 60 @sizes[A, B, C] = ( scalar(@{$adoc}), scalar(@{$bdoc}), scalar(@{$cdoc}) );
227  
228 60 my @matches;
229 60 $#matches = 32;
230  
231 60 my $callback = 0;
232  
233 60 ▶ my $noop = sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
234  
235 # Callback_Map is indexed by the sum of AB_A, AB_B, ..., as indicated by @matches
236 # this isn't the most efficient, but it's a bit easier to maintain and
237 # read than if it were broken up into separate arrays
238 # half the entries are not $noop - it would seem then that no
239 # entries should be $noop. I need patterns to figure out what the
240 # other entries are.
241  
242 60 my @Callback_Map = (
243 [ $no_change, A, B, C ], # 0 - no matches
244 #[ $noop, ], # 1 - BC_C
245 [ $b_diff, A, C ], # 1 - BC_C
246 [ $b_diff, B ], #*2 - BC_B
247 [ $noop, ], # 3 - BC_B BC_C
248 [ $noop, ], # 4 - AC_C
249 [ $c_diff, C ], # 5 - AC_C BC_C
250 [ $noop, ], # 6 - AC_C BC_B
251 [ $noop, ], # 7 - AC_C BC_B BC_C
252 [ $a_diff, A ], # 8 - AC_A
253 [ $noop, ], # 9 - AC_A BC_C
254 [ $c_diff, A, B ], # 10 - AC_A BC_B
255 [ $c_diff, A, B, ], # 11 - AC_A BC_B BC_C
256 [ $noop, ], # 12 - AC_A AC_C
257 [ $noop, ], # 13 - AC_A AC_C BC_C
258 [ $c_diff, A, B, ], # 14 - AC_A AC_C BC_B
259 [ $c_diff, A, B, C ], # 15 - AC_A AC_C BC_B BC_C
260 [ $noop, ], # 16 - AB_B
261 [ $no_change, ], # 17 - AB_B BC_C
262 [ $b_diff, B ], # 18 - AB_B BC_B
263 [ $noop, ], # 19 - AB_B BC_B BC_C
264 [ $a_diff, B, C ], # 20 - AB_B AC_C
265 [ $noop, ], # 21 - AB_B AC_C BC_C
266 [ $noop, ], # 22 - AB_B AC_C BC_B
267 [ $conflict, D, B, C ], # 23 - AB_B AC_C BC_B BC_C
268 [ $b_diff, B ], # 24 - AB_B AC_A
269 [ $noop, ], # 25 - AB_B AC_A BC_C
270 [ $c_diff, D, B, C ], # 26 - AB_B AC_A BC_B
271 [ $noop, ], # 27 - AB_B AC_A BC_B BC_C
272 [ $a_diff, B, C ], # 28 - AB_B AC_A AC_C
273 [ $noop, ], # 29 - AB_B AC_A AC_C BC_C
274 [ $noop, ], # 30 - AB_B AC_A AC_C BC_B
275 [ $b_diff, B ], # 31 - AB_B AC_A AC_C BC_B BC_C
276 [ $no_change, A, B, C ], # 32 - AB_A
277 [ $b_diff, A, C ], # 33 - AB_A BC_C
278 [ $noop, ], # 34 - AB_A BC_B
279 [ $b_diff, A, C ], # 35 - AB_A BC_B BC_C
280 [ $noop, ], # 36 - AB_A AC_C
281 [ $noop, ], # 37 - AB_A AC_C BC_C
282 [ $noop, ], # 38 - AB_A AC_C BC_B
283 [ $noop, ], # 39 - AB_A AC_C BC_B BC_C
284 [ $a_diff, A, ], # 40 - AB_A AC_A
285 [ $noop, ], # 41 - AB_A AC_A BC_C
286 [ $a_diff, A ], # 42 - AB_A AC_A BC_B
287 [ $noop, ], # 43 - AB_A AC_A BC_B BC_C
288 [ $noop, ], # 44 - AB_A AC_A AC_C
289 [ $c_diff, A, D, C ], # 45 - AB_A AC_A AC_C BC_C
290 [ $noop, ], # 46 - AB_A AC_A AC_C BC_B
291 [ $noop, ], # 47 - AB_A AC_A AC_C BC_B BC_C
292 [ $noop, ], # 48 - AB_A AB_B
293 [ $b_diff, A, C ], # 49 - AB_A AB_B BC_C
294 [ $noop, ], # 50 - AB_A AB_B BC_B
295 [ $b_diff, A, B, C ], # 51 - AB_A AB_B BC_B BC_C
296 [ $a_diff, B, C ], # 52 - AB_A AB_B AC_C
297 [ $noop, ], # 53 - AB_A AB_B AC_C BC_C
298 [ $noop, ], # 54 - AB_A AB_B AC_C BC_B
299 [ $c_diff, C ], # 55 - AB_A AB_B AC_C BC_B BC_C
300 [ $b_diff, A, C ], # 56 - AB_A AB_B AC_A
301 [ $noop, ], # 57 - AB_A AB_B AC_A BC_C
302 [ $b_diff, A, B, D ], # 58 - AB_A AB_B AC_A BC_B
303 [ $noop, ], # 59 - AB_A AB_B AC_A BC_B BC_C
304 [ $a_diff, A, B, C ], # 60 - AB_A AB_B AC_A AC_C
305 [ $conflict, A, D, C ], # 61 - AB_A AB_B AC_A AC_C BC_C
306 [ $conflict, A, B, D ], # 62 - AB_A AB_B AC_A AC_C BC_B
307 [ $conflict, A, B, C ], # 63 - AB_A AB_B AC_A AC_C BC_B BC_C
308 );
309  
310 60 my $t; # temporary values
311  
312 # while we have something to work with...
313 60 ▶ while((grep { scalar(@{$_}) > 0 } values %diffs)
Branch: 1 branch
BranchTrueFalseTotal
if (grep {scalar @{$_;} > 0;} values %diffs and grep {$pos[$_] < $sizes[$_];} 4, 2, 1) 309 59 368
Condition100%3/3
grep {scalar @{$_;} > 0;} values %diffs and grep {$pos[$_] < $sizes[$_];} 4, 2, 1
!ll&&!rl&&r
2435309
MC/DC100%2/2
grep {scalar @{$_;} > 0;} values %diffs and grep {$pos[$_] < $sizes[$_];} 4, 2, 1
grep {scalar @{$_;} > 0;} values %diffs grep {$pos[$_] < $sizes[$_];} 4, 2, 1
Truth table100%3/3
A and B
A= grep {scalar @{$_;} > 0;} values %diffsB= grep {$pos[$_] < $sizes[$_];} 4, 2, 1
ABresult
0X0
100
111
314 1032 && (grep { $pos[$_] < $sizes[$_] } (A, B, C)))
315 {
316  
317 309 @matches[AB_A, AB_B, AC_A, AC_C, BC_B, BC_C] = undef;
318  
319 309 foreach my $i (A, B, C) {
320 927 foreach my $j (A, B, C) {
321 2781 ▶ next if $i == $j;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $j 927 1854 2781
322 1854 $t = $abc_s[($i|$j) * 8 | $i];
323 1854 ▶ $matches[$t] = 1 if @{$diffs{$t}} && $pos[$i] == $diffs{$t} -> [0];
Branch: 1 branch
BranchTrueFalseTotal
if @{$diffs{$t};} and $pos[$i] == $diffs{$t}[0] 534 1320 1854
Condition100%3/3
@{$diffs{$t};} and $pos[$i] == $diffs{$t}[0]
!ll&&!rl&&r
751569534
MC/DC100%2/2
@{$diffs{$t};} and $pos[$i] == $diffs{$t}[0]
@{$diffs{$t};} $pos[$i] == $diffs{$t}[0]
Truth table100%3/3
A and B
A= @{$diffs{$t};}B= $pos[$i] == $diffs{$t}[0]
ABresult
0X0
100
111
324 }
325 }
326
327 309 $callback = 0;
328 309 $callback |= $_ foreach grep { $matches[$_] } ( AB_A, AB_B, AC_A, AC_C, BC_B, BC_C );
329  
330 309 my @args = @{$Callback_Map[$callback]};
331 309 ▶ diag(">>>>>> We hit a noop") if @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 1 308 309
332 309 my $f = shift @args;
333 309 diag(join "", "callback: $callback - \@pos: ", join(", ", @pos[A, B, C]), "\n");
334 309 ▶ diag(">>>>>> Callback is a no-op") unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 308 309
335 309 ▶ diag(join "", " matches: ", join(", ", map { defined($_) ? $_ : 'undef' } @matches[AB_A, AB_B, AC_A, AC_C, BC_B, BC_C]), "\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 534 1320 1854
336 309 ▶ diag(join "", " diffs: ", join(", ", map { defined($_) ? $_ : 'undef' } map { $diffs{$_}->[0] } (AB_A, AB_B, AC_A, AC_C, BC_B, BC_C)), "\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1103 751 1854
337 309 ▶ diag(join "", "args: ", join(", ", map { (qw(- C B - A - - - D))[$_] } @args), "(", join(", ", map { defined($_) ? $_ : 'undef' } @pos[@args]), ")\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 745 17 762
338 309 diag('--------------------');
339 309 &{$f}(@pos[@args]);
340 309 foreach (@args) {
341 762 ▶ $pos[$_]++ unless $_ == D;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ == 8 745 17 762
342 762 ▶ if($_ eq A) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ eq 4) { } 259 503 762
elsif ($_ eq 2) { } 241 262 503
elsif ($_ eq 1) { } 245 17 262
343 259 ▶ shift @{$diffs{&AB_A}} while @{$diffs{&AB_A}} && $diffs{&AB_A}[0] < $pos[$_];# if $matches[AB_A];
Branch: 1 branch
BranchTrueFalseTotal
@{$diffs{&AB_A};} and $diffs{&AB_A}[0] < $pos[$_] and do { shift @{$diffs{&AB_A};} } 91 259 350
Condition100%3/3
@{$diffs{&AB_A};} and $diffs{&AB_A}[0] < $pos[$_]
!ll&&!rl&&r
12813191
MC/DC100%2/2
@{$diffs{&AB_A};} and $diffs{&AB_A}[0] < $pos[$_]
@{$diffs{&AB_A};} $diffs{&AB_A}[0] < $pos[$_]
Truth table100%3/3
A and B
A= @{$diffs{&AB_A};}B= $diffs{&AB_A}[0] < $pos[$_]
ABresult
0X0
100
111
344 259 ▶ shift @{$diffs{&AC_A}} while @{$diffs{&AC_A}} && $diffs{&AC_A}[0] < $pos[$_];#if $matches[AC_A];
Branch: 1 branch
BranchTrueFalseTotal
@{$diffs{&AC_A};} and $diffs{&AC_A}[0] < $pos[$_] and do { shift @{$diffs{&AC_A};} } 89 259 348
Condition100%3/3
@{$diffs{&AC_A};} and $diffs{&AC_A}[0] < $pos[$_]
!ll&&!rl&&r
12913089
MC/DC100%2/2
@{$diffs{&AC_A};} and $diffs{&AC_A}[0] < $pos[$_]
@{$diffs{&AC_A};} $diffs{&AC_A}[0] < $pos[$_]
Truth table100%3/3
A and B
A= @{$diffs{&AC_A};}B= $diffs{&AC_A}[0] < $pos[$_]
ABresult
0X0
100
111
345 } elsif($_ eq B) {
346 241 ▶ shift @{$diffs{&AB_B}} while @{$diffs{&AB_B}} && $diffs{&AB_B}[0] < $pos[$_];#if $matches[AB_B];
Branch: 1 branch
BranchTrueFalseTotal
@{$diffs{&AB_B};} and $diffs{&AB_B}[0] < $pos[$_] and do { shift @{$diffs{&AB_B};} } 73 241 314
Condition100%3/3
@{$diffs{&AB_B};} and $diffs{&AB_B}[0] < $pos[$_]
!ll&&!rl&&r
12911273
MC/DC100%2/2
@{$diffs{&AB_B};} and $diffs{&AB_B}[0] < $pos[$_]
@{$diffs{&AB_B};} $diffs{&AB_B}[0] < $pos[$_]
Truth table100%3/3
A and B
A= @{$diffs{&AB_B};}B= $diffs{&AB_B}[0] < $pos[$_]
ABresult
0X0
100
111
347 241 ▶ shift @{$diffs{&BC_B}} while @{$diffs{&BC_B}} && $diffs{&BC_B}[0] < $pos[$_];#if $matches[BC_B];
Branch: 1 branch
BranchTrueFalseTotal
@{$diffs{&BC_B};} and $diffs{&BC_B}[0] < $pos[$_] and do { shift @{$diffs{&BC_B};} } 82 241 323
Condition100%3/3
@{$diffs{&BC_B};} and $diffs{&BC_B}[0] < $pos[$_]
!ll&&!rl&&r
13310882
MC/DC100%2/2
@{$diffs{&BC_B};} and $diffs{&BC_B}[0] < $pos[$_]
@{$diffs{&BC_B};} $diffs{&BC_B}[0] < $pos[$_]
Truth table100%3/3
A and B
A= @{$diffs{&BC_B};}B= $diffs{&BC_B}[0] < $pos[$_]
ABresult
0X0
100
111
348 } elsif($_ eq C) {
349 245 ▶ shift @{$diffs{&AC_C}} while @{$diffs{&AC_C}} && $diffs{&AC_C}[0] < $pos[$_];#if $matches[AC_C];
Branch: 1 branch
BranchTrueFalseTotal
@{$diffs{&AC_C};} and $diffs{&AC_C}[0] < $pos[$_] and do { shift @{$diffs{&AC_C};} } 75 245 320
Condition100%3/3
@{$diffs{&AC_C};} and $diffs{&AC_C}[0] < $pos[$_]
!ll&&!rl&&r
12512075
MC/DC100%2/2
@{$diffs{&AC_C};} and $diffs{&AC_C}[0] < $pos[$_]
@{$diffs{&AC_C};} $diffs{&AC_C}[0] < $pos[$_]
Truth table100%3/3
A and B
A= @{$diffs{&AC_C};}B= $diffs{&AC_C}[0] < $pos[$_]
ABresult
0X0
100
111
350 245 ▶ shift @{$diffs{&BC_C}} while @{$diffs{&BC_C}} && $diffs{&BC_C}[0] < $pos[$_];#if $matches[BC_C];
Branch: 1 branch
BranchTrueFalseTotal
@{$diffs{&BC_C};} and $diffs{&BC_C}[0] < $pos[$_] and do { shift @{$diffs{&BC_C};} } 86 245 331
Condition100%3/3
@{$diffs{&BC_C};} and $diffs{&BC_C}[0] < $pos[$_]
!ll&&!rl&&r
12611986
MC/DC100%2/2
@{$diffs{&BC_C};} and $diffs{&BC_C}[0] < $pos[$_]
@{$diffs{&BC_C};} $diffs{&BC_C}[0] < $pos[$_]
Truth table100%3/3
A and B
A= @{$diffs{&BC_C};}B= $diffs{&BC_C}[0] < $pos[$_]
ABresult
0X0
100
111
351 }
352 }
353 309 ▶ last unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 308 309
354 }
355  
356 60 my $switch;
357 my @args;
358  
359 60 ▶ while(grep { $pos[$_] < $sizes[$_] } (A, B, C)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$pos[$_] < $sizes[$_];} 4, 2, 1) 24 60 84
360 24 $switch = 0;
361 24 @args = ();
362 24 foreach my $i (A, B, C) {
363 72 ▶ if($pos[$i] < $sizes[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos[$i] < $sizes[$i]) 67 5 72
364 #warn "$i: $pos[$i] < $sizes[$i]\n";
365 67 $switch |= $i;
366 #warn "switch: $switch\n";
367 67 push @args, $pos[$i]++;
368 }
369 }
370  
371 24 my $match = $switch;
372 24 $switch = ( 0, 5, 24, 17, 34, 8, 10, 0 )[$switch];
373 #main::diag(join"", "callback: $switch - \@pos: ", join(", ", @pos[A, B, C]));
374 #main::diag(join"", " match: $match");
375 24 ▶ &{$Callback_Map[$switch][0]}(@args)
Branch: 1 branch
BranchTrueFalseTotal
if $Callback_Map[$switch] 24 0 24
376 if $Callback_Map[$switch];
377 }
378 }
379  
380 40 ▶sub merge {
Subroutine merge: called CC=20 SCAR=30.5
Pod documented
381 40 my $pivot = shift; # array ref
382 40 my $doca = shift; # array ref
383 40 my $docb = shift; # array ref
384 40 ▶ my $callbacks = shift || {};
Condition50%1/2
shift() || {}
l!l
400
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
385 40 my $keyGen = shift;
386  
387 0 ▶ my $conflictCallback = $callbacks -> {'CONFLICT'} || sub ($$) { (
Subroutine __ANON__: not called CC=1 SCAR=6.9
388 q{<!-- ------ START CONFLICT ------ -->},
389 0 (@{$_[0]}),
390 q{<!-- ---------------------------- -->},
391 0 (@{$_[1]}),
392 q{<!-- ------ END CONFLICT ------ -->},
393 40 ▶ ) };
Condition33%1/3
$callbacks->{'CONFLICT'} || sub ($$) { '<!-- ------ START CONFLICT ------ -->', @{$_[0];}, '<!-- ---------------------------- -->', @{$_[1];}, '<!-- ------ END CONFLICT ------ -->'; }
l!l&&r!l&&!r
4000
MC/DC0%0/2
$callbacks->{'CONFLICT'} || sub ($$) { '<!-- ------ START CONFLICT ------ -->', @{$_[0];}, '<!-- ---------------------------- -->', @{$_[1];}, '<!-- ------ END CONFLICT ------ -->'; }
$callbacks->{'CONFLICT'} sub ($$) { '<!-- ------ START CONFLICT ------ -->', @{$_[0];}, '<!-- ---------------------------- -->', @{$_[1];}, '<!-- ------ END CONFLICT ------ -->'; }
Truth table33%1/3
A || B
A= $callbacks->{'CONFLICT'}B= sub ($$) { '<!-- ------ START CONFLICT ------ -->', @{$_[0];}, '<!-- ---------------------------- -->', @{$_[1];}, '<!-- ------ END CONFLICT ------ -->'; }
ABresult
1X1
011
000
394  
395 40 my $diff = diff3($pivot, $doca, $docb, $keyGen, @_);
396  
397 # print Data::Dumper -> Dump([$diff]), "\n";
398  
399 40 my @ret;
400  
401 40 my @conflict = ( [], [] );
402  
403 40 foreach my $h (@{$diff}) {
404 282 my $i = 0;
405 #print "op: ", $h -> [0];
406 282 ▶ if($h -> [0] eq 'c') { # conflict
Branch: 1 branch
BranchTrueFalseTotal
if ($h->[0] eq 'c') { } 22 260 282
407 22 ▶ push @{$conflict[0]}, $h -> [2] if defined $h -> [2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->[2] 21 1 22
408 22 ▶ push @{$conflict[1]}, $h -> [3] if defined $h -> [3];
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->[3] 21 1 22
409 }
410 else {
411 260 ▶ if(@{$conflict[0]} || @{$conflict[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$conflict[0];} or @{$conflict[1];}) 18 242 260
Condition100%3/3
@{$conflict[0];} or @{$conflict[1];}
l!l&&r!l&&!r
171242
MC/DC100%2/2
@{$conflict[0];} or @{$conflict[1];}
@{$conflict[0];} @{$conflict[1];}
Truth table100%3/3
A or B
A= @{$conflict[0];}B= @{$conflict[1];}
ABresult
1X1
011
000
412 18 push @ret, &$conflictCallback(@conflict);
413 18 @conflict = ( [], [] );
414 }
415 260 ▶ if($h -> [0] eq 'u') { # unchanged
Branch: 4 branches
BranchTrueFalseTotal
if ($h->[0] eq 'u') { } 140 120 260
elsif ($h->[0] eq 'o') { } 41 79 120
elsif ($h->[0] eq 'l') { } 39 40 79
elsif ($h->[0] eq 'r') { } 40 0 40
416 140 ▶ push @ret, $h -> [2] || $h -> [3];
Condition66%2/3
$h->[2] || $h->[3]
l!l&&r!l&&!r
13406
MC/DC50%1/2
$h->[2] || $h->[3]
$h->[2] $h->[3]
Truth table66%2/3
A || B
A= $h->[2]B= $h->[3]
ABresult
1X1
011
000
417 }
418 elsif($h -> [0] eq 'o') { # added
419 41 ▶ push @ret, $h -> [2] if defined $h -> [2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->[2] 18 23 41
420 }
421 elsif($h -> [0] eq 'l') { # added by left
422 39 ▶ push @ret, $h -> [2] if defined $h -> [2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->[2] 20 19 39
423 }
424 elsif($h -> [0] eq 'r') { # added by right
425 40 ▶ push @ret, $h -> [3] if defined $h -> [3];
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->[3] 20 20 40
426 }
427 }
428 #print " : ", join(" ", @ret), " [$$h[1],$$h[2],$$h[3]]\n";
429 }
430  
431 40 ▶ if(@{$conflict[0]} || @{$conflict[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$conflict[0];} or @{$conflict[1];}) 2 38 40
Condition66%2/3
@{$conflict[0];} or @{$conflict[1];}
l!l&&r!l&&!r
2038
MC/DC50%1/2
@{$conflict[0];} or @{$conflict[1];}
@{$conflict[0];} @{$conflict[1];}
Truth table66%2/3
A or B
A= @{$conflict[0];}B= @{$conflict[1];}
ABresult
1X1
011
000
432 2 push @ret, &$conflictCallback(@conflict);
433 }
434  
435 40 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 40 40
436 0 return @ret;
437 }
438 40 return \@ret;
439 }
440  
441  
442 __END__
↑ Summary