Diff3/DiffHeckel.pm

filter: Statementstmt 94.2% 65 / 69 Branchbran 86.3% 19 / 22 Conditioncond 69.4% 25 / 36 MC/DCmcdc 44.4% 8 / 18 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 81.7% 125 / 153 CC 27 SCAR 28.7
CC
27
Cov
86%
diff
23.7
_is_a_text
6.9
BEGIN
1.0
CRAP 17.7
↑ Summary Diff3.pm »
1 package Text::Diff3::DiffHeckel;
2 # two-way diff plug-in
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use base qw(Text::Diff3::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use version; our $VERSION = '0.08';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 48 ▶sub diff {
Subroutine diff: called CC=23 SCAR=31.6
Pod documented
11 48 my($self, $A, $B) = @_;
12 48 my $f = $self->factory;
13 48 ▶ if (! $self->_is_a_text($A)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a_text($A)) 0 48 48
14 0 $A = $f->create_text($A);
15 }
16 48 ▶ if (! $self->_is_a_text($B)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a_text($B)) 0 48 48
17 0 $B = $f->create_text($B);
18 }
19 48 my $diff = $f->create_list2;
20 48 my @uniq = (
21 [$A->first_index - 1, $B->first_index - 1],
22 [$A->last_index + 1, $B->last_index + 1]
23 );
24 48 my(%freq, %ap, %bp);
25 48 for my $lineno ($A->range) {
26 289 my $s = $A->at($lineno);
27 289 $freq{$s} += 2;
28 289 $ap{$s} = $lineno;
29 }
30 48 for my $lineno ($B->range) {
31 301 my $s = $B->at($lineno);
32 301 $freq{$s} += 3;
33 301 $bp{$s} = $lineno;
34 }
35 48 ▶ while (my($s, $x) = each %freq) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %freq) 354 48 402
36 354 ▶ next if $x != 5;
Branch: 1 branch
BranchTrueFalseTotal
if $x != 5 129 225 354
37 225 push @uniq, [$ap{$s}, $bp{$s}];
38 }
39 48 @uniq = sort { $a->[0] <=> $b->[0] } @uniq;
40 48 my($AL, $BL) = ($A->last_index, $B->last_index);
41 48 my($a1, $b1) = ($A->first_index, $B->first_index);
42 48 ▶ while ($a1 <= $AL && $b1 <= $BL && $A->eq_at($a1, $B->at($b1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a1 <= $AL and $b1 <= $BL and $A->eq_at($a1, $B->at($b1))) 138 48 186
Condition100%6/6
$a1 <= $AL and $b1 <= $BL and $A->eq_at($a1, $B->at($b1))
!ll&&!rl&&r
2226138
$a1 <= $AL and $b1 <= $BL
!ll&&!rl&&r
193164
MC/DC100%3/3
$a1 <= $AL and $b1 <= $BL and $A->eq_at($a1, $B->at($b1))
$a1 <= $AL $b1 <= $BL $A->eq_at($a1, $B->at($b1))
Truth table100%4/4
A and B and C
A= $a1 <= $ALB= $b1 <= $BLC= $A->eq_at($a1, $B->at($b1))
ABCresult
0XX0
10X0
1100
1111
43 138 $a1++;
44 138 $b1++;
45 }
46 48 my($a0, $b0) = ($a1, $b1);
47 48 for (@uniq) {
48 321 my($auniq, $buniq) = @{$_};
49 321 ▶ next if $auniq < $a0 || $buniq < $b0;
Branch: 1 branch
BranchTrueFalseTotal
if $auniq < $a0 or $buniq < $b0 231 90 321
Condition66%2/3
$auniq < $a0 or $buniq < $b0
l!l&&r!l&&!r
231090
MC/DC50%1/2
$auniq < $a0 or $buniq < $b0
$auniq < $a0 $buniq < $b0
Truth table66%2/3
A or B
A= $auniq < $a0B= $buniq < $b0
ABresult
1X1
011
000
50 90 ($a1, $b1) = ($auniq - 1, $buniq - 1);
51 90 ▶ while ($a0 <= $a1 && $b0 <= $b1 && $A->eq_at($a1, $B->at($b1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a0 <= $a1 and $b0 <= $b1 and $A->eq_at($a1, $B->at($b1))) 0 90 90
Condition83%5/6
$a0 <= $a1 and $b0 <= $b1 and $A->eq_at($a1, $B->at($b1))
!ll&&!rl&&r
74160
$a0 <= $a1 and $b0 <= $b1
!ll&&!rl&&r
591516
MC/DC0%0/3
$a0 <= $a1 and $b0 <= $b1 and $A->eq_at($a1, $B->at($b1))
$a0 <= $a1 $b0 <= $b1 $A->eq_at($a1, $B->at($b1))
Truth table75%3/4
A and B and C
A= $a0 <= $a1B= $b0 <= $b1C= $A->eq_at($a1, $B->at($b1))
ABCresult
0XX0
10X0
1100
1111
52 0 $a1--;
53 0 $b1--;
54 }
55 90 ▶ if ($a0 <= $a1 && $b0 <= $b1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($a0 <= $a1 and $b0 <= $b1) { } 16 74 90
elsif ($a0 <= $a1) { } 15 59 74
elsif ($b0 <= $b1) { } 20 39 59
Condition100%3/3
$a0 <= $a1 and $b0 <= $b1
!ll&&!rl&&r
591516
MC/DC100%2/2
$a0 <= $a1 and $b0 <= $b1
$a0 <= $a1 $b0 <= $b1
Truth table100%3/3
A and B
A= $a0 <= $a1B= $b0 <= $b1
ABresult
0X0
100
111
56 16 $diff->push($f->create_range2('c', $a0, $a1, $b0, $b1));
57 } elsif ($a0 <= $a1) {
58 15 $diff->push($f->create_range2('d', $a0, $a1, $b0, $b0 - 1));
59 } elsif ($b0 <= $b1) {
60 20 $diff->push($f->create_range2('a', $a0, $a0 - 1, $b0, $b1));
61 }
62 90 ($a1, $b1) = ($auniq + 1, $buniq + 1);
63 90 ▶ while ($a1 <= $AL && $b1 <= $BL && $A->eq_at($a1, $B->at($b1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a1 <= $AL and $b1 <= $BL and $A->eq_at($a1, $B->at($b1))) 45 90 135
Condition83%5/6
$a1 <= $AL and $b1 <= $BL and $A->eq_at($a1, $B->at($b1))
!ll&&!rl&&r
741645
$a1 <= $AL and $b1 <= $BL
!ll&&!rl&&r
74061
MC/DC66%2/3
$a1 <= $AL and $b1 <= $BL and $A->eq_at($a1, $B->at($b1))
$a1 <= $AL $b1 <= $BL $A->eq_at($a1, $B->at($b1))
Truth table75%3/4
A and B and C
A= $a1 <= $ALB= $b1 <= $BLC= $A->eq_at($a1, $B->at($b1))
ABCresult
0XX0
10X0
1100
1111
64 45 $a1++;
65 45 $b1++;
66 }
67 90 ($a0, $b0) = ($a1, $b1);
68 }
69 48 return $diff;
70 }
71  
72 96 ▶sub _is_a_text {
Subroutine _is_a_text: called CC=5 SCAR=19.3
73 96 my($self, $x) = @_;
74 96 return eval{ $x->can('first_index') }
75 96 && eval{ $x->can('last_index') }
76 96 && eval{ $x->can('range') }
77 96 && eval{ $x->can('at') }
78 96 ▶ && eval{ $x->can('eq_at') };
Condition33%4/12
eval { do { $x->can('first_index') } } && eval { do { $x->can('last_index') } } && eval { do { $x->can('range') } } && eval { do { $x->can('at') } } && eval { do { $x->can('eq_at') } }
!ll&&!rl&&r
0096
eval { do { $x->can("first_index") } } and eval { do { $x->can("last_index") } } and eval { do { $x->can("range") } } and eval { do { $x->can("at") } }
!ll&&!rl&&r
0096
eval { do { $x->can("first_index") } } and eval { do { $x->can("last_index") } } and eval { do { $x->can("range") } }
!ll&&!rl&&r
0096
eval { do { $x->can("first_index") } } and eval { do { $x->can("last_index") } }
!ll&&!rl&&r
0096
MC/DC0%0/5
eval { do { $x->can('first_index') } } && eval { do { $x->can('last_index') } } && eval { do { $x->can('range') } } && eval { do { $x->can('at') } } && eval { do { $x->can('eq_at') } }
eval { do { $x->can("first_index") } } eval { do { $x->can("last_index") } } eval { do { $x->can("range") } } eval { do { $x->can("at") } } eval { do { $x->can('eq_at') } }
Truth table16%1/6
A and B and C and D && E
A= eval { do { $x->can("first_index") } }B= eval { do { $x->can("last_index") } }C= eval { do { $x->can("range") } }D= eval { do { $x->can("at") } }E= eval { do { $x->can('eq_at') } }
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
79 }
80  
81 6 1;
82  
83 __END__
↑ Summary Diff3.pm »