lib/Algorithm/Diff.pm

filter: Statementstmt 89.7% 331 / 369 Branchbran 80.3% 135 / 168 Conditioncond 73.2% 74 / 101 MC/DCmcdc 54.8% 34 / 62 Subroutinesub 80.7% 42 / 52 Podpod 100% 9 / 9 totaltotal 82.1% 625 / 761 SCAR 52.1
CC
126
Cov
85%
_longestCommonSubsequence
34.0
traverse_sequences
24.9
_replaceNextLargerWith
21.5
CRAP 183.5
« blib/lib/Algorithm/DiffOld.pm ↑ Summary blib/lib/Algorithm/diff.pl »
1 package Algorithm::Diff;
2 # Skip to first "=head" line for documentation.
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use integer; # see below in _replaceNextLargerWith() for mod to make
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # if you don't use this
7 2 ▶use vars qw( $VERSION @EXPORT_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 $VERSION = 1.19_03;
9 # ^ ^^ ^^-- Incremented at will
10 # | \+----- Incremented for non-trivial changes to features
11 # \-------- Incremented for fundamental changes
12 2 require Exporter;
13 2 *import = \&Exporter::import;
14 2 @EXPORT_OK = qw(
15 prepare LCS LCSidx LCS_length
16 diff sdiff compact_diff
17 traverse_sequences traverse_balanced
18 );
19  
20 # McIlroy-Hunt diff algorithm
21 # Adapted from the Smalltalk code of Mario I. Wolczko, <mario@wolczko.com>
22 # by Ned Konz, perl@bike-nomad.com
23 # Updates by Tye McQueen, http://perlmonks.org/?node=tye
24  
25 # Create a hash that maps each element of $aCollection to the set of
26 # positions it occupies in $aCollection, restricted to the elements
27 # within the range of indexes specified by $start and $end.
28 # The fourth parameter is a subroutine reference that will be called to
29 # generate a string to use as a key.
30 # Additional parameters, if any, will be passed to this subroutine.
31 #
32 # my $hashRef = _withPositionsOfInInterval( \@array, $start, $end, $keyGen );
33  
34 sub _withPositionsOfInInterval
35 {
36 36 ▶ my $aCollection = shift; # array ref
Subroutine _withPositionsOfInInterval: called CC=4 SCAR=13.9
37 36 my $start = shift;
38 36 my $end = shift;
39 36 my $keyGen = shift;
40 36 my %d;
41 my $index;
42 36 ▶ for ( $index = $start ; $index <= $end ; $index++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($index <= $end) 154 36 190
43 {
44 154 my $element = $aCollection->[$index];
45 154 my $key = &$keyGen( $element, @_ );
46 154 ▶ if ( exists( $d{$key} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $d{$key}) { } 1 153 154
47 {
48 1 unshift ( @{ $d{$key} }, $index );
49 }
50 else
51 {
52 153 $d{$key} = [$index];
53 }
54 }
55 36 ▶ return wantarray ? %d : \%d;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 36 36
56 }
57  
58 # Find the place at which aValue would normally be inserted into the
59 # array. If that place is already occupied by aValue, do nothing, and
60 # return undef. If the place does not exist (i.e., it is off the end of
61 # the array), add it to the end, otherwise replace the element at that
62 # point with aValue. It is assumed that the array's values are numeric.
63 # This is where the bulk (75%) of the time is spent in this module, so
64 # try to make it fast!
65  
66 sub _replaceNextLargerWith
67 {
68 55 ▶ my ( $array, $aValue, $high ) = @_;
Subroutine _replaceNextLargerWith: called CC=7 SCAR=30.7
69 55 ▶ $high ||= $#$array;
Condition66%2/3
$high ||= $array->$#*
l!l&&r!l&&!r
04411
MC/DC50%1/2
$high ||= $array->$#*
$high $array->$#*
Truth table66%2/3
A ||= B
A= $highB= $array->$#*
ABresult
1X1
011
000
70  
71 # off the end?
72 55 ▶ if ( $high == -1 || $aValue > $array->[-1] )
Branch: 1 branch
BranchTrueFalseTotal
if ($high == -1 or $aValue > $array->[-1]) 55 0 55
Condition66%2/3
$high == -1 or $aValue > $array->[-1]
l!l&&r!l&&!r
14410
MC/DC0%0/2
$high == -1 or $aValue > $array->[-1]
$high == -1 $aValue > $array->[-1]
Truth table66%2/3
A or B
A= $high == -1B= $aValue > $array->[-1]
ABresult
1X1
011
000
73 {
74 55 push ( @$array, $aValue );
75 55 return $high + 1;
76 }
77  
78 # binary search for insertion point...
79 0 my $low = 0;
80 0 my $index;
81 my $found;
82 0 ▶ while ( $low <= $high )
Branch: 1 branch
BranchTrueFalseTotal
if ($low <= $high) 0 0 0
83 {
84 0 $index = ( $high + $low ) / 2;
85  
86 # $index = int(( $high + $low ) / 2); # without 'use integer'
87 0 $found = $array->[$index];
88  
89 0 ▶ if ( $aValue == $found )
Branch: 2 branches
BranchTrueFalseTotal
if ($aValue == $found) { } 0 0 0
elsif ($aValue > $found) { } 0 0 0
90 {
91 0 return undef;
92 }
93 elsif ( $aValue > $found )
94 {
95 0 $low = $index + 1;
96 }
97 else
98 {
99 0 $high = $index - 1;
100 }
101 }
102  
103 # now insertion point is in $low.
104 0 $array->[$low] = $aValue; # overwrite next larger
105 0 return $low;
106 }
107  
108 # This method computes the longest common subsequence in $a and $b.
109  
110 # Result is array or ref, whose contents is such that
111 # $a->[ $i ] == $b->[ $result[ $i ] ]
112 # foreach $i in ( 0 .. $#result ) if $result[ $i ] is defined.
113  
114 # An additional argument may be passed; this is a hash or key generating
115 # function that should return a string that uniquely identifies the given
116 # element. It should be the case that if the key is the same, the elements
117 # will compare the same. If this parameter is undef or missing, the key
118 # will be the element as a string.
119  
120 # By default, comparisons will use "eq" and elements will be turned into keys
121 # using the default stringizing operator '""'.
122  
123 # Additional parameters, if any, will be passed to the key generation
124 # routine.
125  
126 sub _longestCommonSubsequence
127 {
128 36 ▶ my $a = shift; # array ref or hash ref
Subroutine _longestCommonSubsequence: called CC=25 SCAR=35.3
129 36 my $b = shift; # array ref or hash ref
130 36 my $counting = shift; # scalar
131 36 my $keyGen = shift; # code ref
132 36 my $compare; # code ref
133  
134 36 ▶ if ( ref($a) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a eq "HASH") 0 36 36
135 { # prepared hash must be in $b
136 0 my $tmp = $b;
137 0 $b = $a;
138 0 $a = $tmp;
139 }
140  
141 # Check for bogus (non-ref) argument values
142 36 ▶ if ( !ref($a) || !ref($b) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $a and ref $b) 0 36 36
Condition33%1/3
ref $a and ref $b
!ll&&!rl&&r
0036
MC/DC0%0/2
ref $a and ref $b
ref $a ref $b
Truth table33%1/3
A and B
A= ref $aB= ref $b
ABresult
0X0
100
111
143 {
144 0 my @callerInfo = caller(1);
145 0 die 'error: must pass array or hash references to ' . $callerInfo[3];
146 }
147  
148 # set up code refs
149 # Note that these are optimized.
150 36 ▶ if ( !defined($keyGen) ) # optimize for strings
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $keyGen) { } 36 0 36
151 {
152 36 ▶ $keyGen = sub { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
153 36 ▶ $compare = sub { my ( $a, $b ) = @_; $a eq $b };
Subroutine __ANON__: called CC=1 SCAR=0.0
154 }
155 else
156 {
157 $compare = sub {
158 0 ▶ my $a = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
159 0 my $b = shift;
160 0 &$keyGen( $a, @_ ) eq &$keyGen( $b, @_ );
161 0 };
162 }
163  
164 36 my ( $aStart, $aFinish, $matchVector ) = ( 0, $#$a, [] );
165 36 my ( $prunedCount, $bMatches ) = ( 0, {} );
166  
167 36 ▶ if ( ref($b) eq 'HASH' ) # was $bMatches prepared for us?
Branch: 1 branch
BranchTrueFalseTotal
if (ref $b eq 'HASH') { } 0 36 36
168 {
169 0 $bMatches = $b;
170 }
171 else
172 {
173 36 my ( $bStart, $bFinish ) = ( 0, $#$b );
174  
175 # First we prune off any common elements at the beginning
176 36 ▶ while ( $aStart <= $aFinish
Branch: 1 branch
BranchTrueFalseTotal
if ($aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aStart], $b->[$bStart], @_)) 13 36 49
Condition100%6/6
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aStart], $b->[$bStart], @_)
!ll&&!rl&&r
72913
$aStart <= $aFinish and $bStart <= $bFinish
!ll&&!rl&&r
4342
MC/DC100%3/3
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aStart], $b->[$bStart], @_)
$aStart <= $aFinish $bStart <= $bFinish &$compare($a->[$aStart], $b->[$bStart], @_)
Truth table100%4/4
A and B and C
A= $aStart <= $aFinishB= $bStart <= $bFinishC= &$compare($a->[$aStart], $b->[$bStart], @_)
ABCresult
0XX0
10X0
1100
1111
177 and $bStart <= $bFinish
178 and &$compare( $a->[$aStart], $b->[$bStart], @_ ) )
179 {
180 13 $matchVector->[ $aStart++ ] = $bStart++;
181 13 $prunedCount++;
182 }
183  
184 # now the end
185 36 ▶ while ( $aStart <= $aFinish
Branch: 1 branch
BranchTrueFalseTotal
if ($aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aFinish], $b->[$bFinish], @_)) 16 36 52
Condition100%6/6
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aFinish], $b->[$bFinish], @_)
!ll&&!rl&&r
132316
$aStart <= $aFinish and $bStart <= $bFinish
!ll&&!rl&&r
6739
MC/DC100%3/3
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aFinish], $b->[$bFinish], @_)
$aStart <= $aFinish $bStart <= $bFinish &$compare($a->[$aFinish], $b->[$bFinish], @_)
Truth table100%4/4
A and B and C
A= $aStart <= $aFinishB= $bStart <= $bFinishC= &$compare($a->[$aFinish], $b->[$bFinish], @_)
ABCresult
0XX0
10X0
1100
1111
186 and $bStart <= $bFinish
187 and &$compare( $a->[$aFinish], $b->[$bFinish], @_ ) )
188 {
189 16 $matchVector->[ $aFinish-- ] = $bFinish--;
190 16 $prunedCount++;
191 }
192  
193 # Now compute the equivalence classes of positions of elements
194 $bMatches =
195 36 _withPositionsOfInInterval( $b, $bStart, $bFinish, $keyGen, @_ );
196 }
197 36 my $thresh = [];
198 36 my $links = [];
199  
200 36 my ( $i, $ai, $j, $k );
201 36 ▶ for ( $i = $aStart ; $i <= $aFinish ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $aFinish) 129 36 165
202 {
203 129 $ai = &$keyGen( $a->[$i], @_ );
204 129 ▶ if ( exists( $bMatches->{$ai} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $bMatches->{$ai}) 55 74 129
205 {
206 55 $k = 0;
207 55 for $j ( @{ $bMatches->{$ai} } )
208 {
209  
210 # optimization: most of the time this will be true
211 55 ▶ if ( $k and $thresh->[$k] > $j and $thresh->[ $k - 1 ] < $j )
Branch: 1 branch
BranchTrueFalseTotal
if ($k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j) { } 0 55 55
Condition33%2/6
$k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j
!ll&&!rl&&r
5500
$k and $thresh->[$k] > $j
!ll&&!rl&&r
5500
MC/DC0%0/3
$k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j
$k $thresh->[$k] > $j $$thresh[$k - 1] < $j
Truth table25%1/4
A and B and C
A= $kB= $thresh->[$k] > $jC= $$thresh[$k - 1] < $j
ABCresult
0XX0
10X0
1100
1111
212 {
213 0 $thresh->[$k] = $j;
214 }
215 else
216 {
217 55 $k = _replaceNextLargerWith( $thresh, $j, $k );
218 }
219  
220 # oddly, it's faster to always test this (CPU cache?).
221 55 ▶ if ( defined($k) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) 55 0 55
222 {
223 55 ▶ $links->[$k] =
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 41 14 55
224 [ ( $k ? $links->[ $k - 1 ] : undef ), $i, $j ];
225 }
226 }
227 }
228 }
229  
230 36 ▶ if (@$thresh)
Branch: 2 branches
BranchTrueFalseTotal
if (@$thresh) { } 14 22 36
elsif ($counting) { } 0 22 22
231 {
232 14 ▶ return $prunedCount + @$thresh if $counting;
Branch: 1 branch
BranchTrueFalseTotal
if $counting 0 14 14
233 14 ▶ for ( my $link = $links->[$#$thresh] ; $link ; $link = $link->[0] )
Branch: 1 branch
BranchTrueFalseTotal
if ($link) 55 14 69
234 {
235 55 $matchVector->[ $link->[1] ] = $link->[2];
236 }
237 }
238 elsif ($counting)
239 {
240 0 return $prunedCount;
241 }
242  
243 36 ▶ return wantarray ? @$matchVector : $matchVector;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 35 36
244 }
245  
246 sub traverse_sequences
247 {
248 3 ▶ my $a = shift; # array ref
Subroutine traverse_sequences: called CC=20 SCAR=32.2
Pod documented
249 3 my $b = shift; # array ref
250 3 ▶ my $callbacks = shift || {};
Condition50%1/2
shift() || {}
l!l
30
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
251 3 my $keyGen = shift;
252 3 ▶ my $matchCallback = $callbacks->{'MATCH'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'MATCH'} || sub { }
l!l&&r!l&&!r
300
MC/DC0%0/2
$callbacks->{'MATCH'} || sub { }
$callbacks->{'MATCH'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'MATCH'}B= sub { }
ABresult
1X1
011
000
253 3 ▶ my $discardACallback = $callbacks->{'DISCARD_A'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_A'} || sub { }
l!l&&r!l&&!r
300
MC/DC0%0/2
$callbacks->{'DISCARD_A'} || sub { }
$callbacks->{'DISCARD_A'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_A'}B= sub { }
ABresult
1X1
011
000
254 3 my $finishedACallback = $callbacks->{'A_FINISHED'};
255 3 ▶ my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_B'} || sub { }
l!l&&r!l&&!r
300
MC/DC0%0/2
$callbacks->{'DISCARD_B'} || sub { }
$callbacks->{'DISCARD_B'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_B'}B= sub { }
ABresult
1X1
011
000
256 3 my $finishedBCallback = $callbacks->{'B_FINISHED'};
257 3 my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ );
258  
259 # Process all the lines in @$matchVector
260 3 my $lastA = $#$a;
261 3 my $lastB = $#$b;
262 3 my $bi = 0;
263 3 my $ai;
264  
265 3 ▶ for ( $ai = 0 ; $ai <= $#$matchVector ; $ai++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($ai <= $matchVector->$#*) 24 3 27
266 {
267 24 my $bLine = $matchVector->[$ai];
268 24 ▶ if ( defined($bLine) ) # matched
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bLine) { } 18 6 24
269 {
270 18 ▶ &$discardBCallback( $ai, $bi++, @_ ) while $bi < $bLine;
Branch: 1 branch
BranchTrueFalseTotal
$bi < $bLine and do { &$discardBCallback($ai, $bi++, @_) } 9 18 27
271 18 &$matchCallback( $ai, $bi++, @_ );
272 }
273 else
274 {
275 6 &$discardACallback( $ai, $bi, @_ );
276 }
277 }
278  
279 # The last entry (if any) processed was a match.
280 # $ai and $bi point just past the last matching lines in their sequences.
281  
282 3 ▶ while ( $ai <= $lastA or $bi <= $lastB )
Branch: 1 branch
BranchTrueFalseTotal
if ($ai <= $lastA or $bi <= $lastB) 9 3 12
Condition100%3/3
$ai <= $lastA or $bi <= $lastB
l!l&&r!l&&!r
633
MC/DC100%2/2
$ai <= $lastA or $bi <= $lastB
$ai <= $lastA $bi <= $lastB
Truth table100%3/3
A or B
A= $ai <= $lastAB= $bi <= $lastB
ABresult
1X1
011
000
283 {
284  
285 # last A?
286 9 ▶ if ( $ai == $lastA + 1 and $bi <= $lastB )
Branch: 1 branch
BranchTrueFalseTotal
if ($ai == $lastA + 1 and $bi <= $lastB) 3 6 9
Condition66%2/3
$ai == $lastA + 1 and $bi <= $lastB
!ll&&!rl&&r
603
MC/DC50%1/2
$ai == $lastA + 1 and $bi <= $lastB
$ai == $lastA + 1 $bi <= $lastB
Truth table66%2/3
A and B
A= $ai == $lastA + 1B= $bi <= $lastB
ABresult
0X0
100
111
287 {
288 3 ▶ if ( defined($finishedACallback) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finishedACallback) { } 1 2 3
289 {
290 1 &$finishedACallback( $lastA, @_ );
291 1 $finishedACallback = undef;
292 }
293 else
294 {
295 2 ▶ &$discardBCallback( $ai, $bi++, @_ ) while $bi <= $lastB;
Branch: 1 branch
BranchTrueFalseTotal
$bi <= $lastB and do { &$discardBCallback($ai, $bi++, @_) } 2 2 4
296 }
297 }
298  
299 # last B?
300 9 ▶ if ( $bi == $lastB + 1 and $ai <= $lastA )
Branch: 1 branch
BranchTrueFalseTotal
if ($bi == $lastB + 1 and $ai <= $lastA) 0 9 9
Condition66%2/3
$bi == $lastB + 1 and $ai <= $lastA
!ll&&!rl&&r
720
MC/DC0%0/2
$bi == $lastB + 1 and $ai <= $lastA
$bi == $lastB + 1 $ai <= $lastA
Truth table66%2/3
A and B
A= $bi == $lastB + 1B= $ai <= $lastA
ABresult
0X0
100
111
301 {
302 0 ▶ if ( defined($finishedBCallback) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finishedBCallback) { } 0 0 0
303 {
304 0 &$finishedBCallback( $lastB, @_ );
305 0 $finishedBCallback = undef;
306 }
307 else
308 {
309 0 ▶ &$discardACallback( $ai++, $bi, @_ ) while $ai <= $lastA;
Branch: 1 branch
BranchTrueFalseTotal
$ai <= $lastA and do { &$discardACallback($ai++, $bi, @_) } 0 0 0
310 }
311 }
312  
313 9 ▶ &$discardACallback( $ai++, $bi, @_ ) if $ai <= $lastA;
Branch: 1 branch
BranchTrueFalseTotal
if $ai <= $lastA 6 3 9
314 9 ▶ &$discardBCallback( $ai, $bi++, @_ ) if $bi <= $lastB;
Branch: 1 branch
BranchTrueFalseTotal
if $bi <= $lastB 7 2 9
315 }
316  
317 3 return 1;
318 }
319  
320 sub traverse_balanced
321 {
322 20 ▶ my $a = shift; # array ref
Subroutine traverse_balanced: called CC=20 SCAR=30.3
Pod documented
323 20 my $b = shift; # array ref
324 20 ▶ my $callbacks = shift || {};
Condition50%1/2
shift() || {}
l!l
200
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
325 20 my $keyGen = shift;
326 20 ▶ my $matchCallback = $callbacks->{'MATCH'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'MATCH'} || sub { }
l!l&&r!l&&!r
2000
MC/DC0%0/2
$callbacks->{'MATCH'} || sub { }
$callbacks->{'MATCH'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'MATCH'}B= sub { }
ABresult
1X1
011
000
327 20 ▶ my $discardACallback = $callbacks->{'DISCARD_A'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_A'} || sub { }
l!l&&r!l&&!r
2000
MC/DC0%0/2
$callbacks->{'DISCARD_A'} || sub { }
$callbacks->{'DISCARD_A'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_A'}B= sub { }
ABresult
1X1
011
000
328 20 ▶ my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_B'} || sub { }
l!l&&r!l&&!r
2000
MC/DC0%0/2
$callbacks->{'DISCARD_B'} || sub { }
$callbacks->{'DISCARD_B'} sub { }
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_B'}B= sub { }
ABresult
1X1
011
000
329 20 my $changeCallback = $callbacks->{'CHANGE'};
330 20 my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ );
331  
332 # Process all the lines in match vector
333 20 my $lastA = $#$a;
334 20 my $lastB = $#$b;
335 20 my $bi = 0;
336 20 my $ai = 0;
337 20 my $ma = -1;
338 20 my $mb;
339  
340 20 while (1)
341 {
342  
343 # Find next match indices $ma and $mb
344 52 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$ma <= $matchVector->$#* and not defined $matchVector->[$ma] and do { do { ++$ma } } 19 52 71
Condition100%3/3
$ma <= $matchVector->$#* and not defined $matchVector->[$ma]
!ll&&!rl&&r
203219
MC/DC100%2/2
$ma <= $matchVector->$#* and not defined $matchVector->[$ma]
$ma <= $matchVector->$#* not defined $matchVector->[$ma]
Truth table100%3/3
A and not(B)
A= $ma <= $matchVector->$#*B= not defined $matchVector->[$ma]
ABresult
0X0
100
111
345 71 $ma++;
346 } while(
347 $ma <= $#$matchVector
348 && !defined $matchVector->[$ma]
349 );
350  
351 52 ▶ last if $ma > $#$matchVector; # end of matchVector?
Branch: 1 branch
BranchTrueFalseTotal
if $ma > $matchVector->$#* 20 32 52
352 32 $mb = $matchVector->[$ma];
353  
354 # Proceed with discard a/b or change events until
355 # next match
356 32 ▶ while ( $ai < $ma || $bi < $mb )
Branch: 1 branch
BranchTrueFalseTotal
if ($ai < $ma or $bi < $mb) 38 32 70
Condition100%3/3
$ai < $ma or $bi < $mb
l!l&&r!l&&!r
191932
MC/DC100%2/2
$ai < $ma or $bi < $mb
$ai < $ma $bi < $mb
Truth table100%3/3
A or B
A= $ai < $maB= $bi < $mb
ABresult
1X1
011
000
357 {
358  
359 38 ▶ if ( $ai < $ma && $bi < $mb )
Branch: 2 branches
BranchTrueFalseTotal
if ($ai < $ma and $bi < $mb) { } 10 28 38
elsif ($ai < $ma) { } 9 19 28
Condition100%3/3
$ai < $ma and $bi < $mb
!ll&&!rl&&r
19910
MC/DC100%2/2
$ai < $ma and $bi < $mb
$ai < $ma $bi < $mb
Truth table100%3/3
A and B
A= $ai < $maB= $bi < $mb
ABresult
0X0
100
111
360 {
361  
362 # Change
363 10 ▶ if ( defined $changeCallback )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $changeCallback) { } 9 1 10
364 {
365 9 &$changeCallback( $ai++, $bi++, @_ );
366 }
367 else
368 {
369 1 &$discardACallback( $ai++, $bi, @_ );
370 1 &$discardBCallback( $ai, $bi++, @_ );
371 }
372 }
373 elsif ( $ai < $ma )
374 {
375 9 &$discardACallback( $ai++, $bi, @_ );
376 }
377 else
378 {
379  
380 # $bi < $mb
381 19 &$discardBCallback( $ai, $bi++, @_ );
382 }
383 }
384  
385 # Match
386 32 &$matchCallback( $ai++, $bi++, @_ );
387 }
388  
389 20 ▶ while ( $ai <= $lastA || $bi <= $lastB )
Branch: 1 branch
BranchTrueFalseTotal
if ($ai <= $lastA or $bi <= $lastB) 22 20 42
Condition100%3/3
$ai <= $lastA or $bi <= $lastB
l!l&&r!l&&!r
17520
MC/DC100%2/2
$ai <= $lastA or $bi <= $lastB
$ai <= $lastA $bi <= $lastB
Truth table100%3/3
A or B
A= $ai <= $lastAB= $bi <= $lastB
ABresult
1X1
011
000
390 {
391 22 ▶ if ( $ai <= $lastA && $bi <= $lastB )
Branch: 2 branches
BranchTrueFalseTotal
if ($ai <= $lastA and $bi <= $lastB) { } 10 12 22
elsif ($ai <= $lastA) { } 7 5 12
Condition100%3/3
$ai <= $lastA and $bi <= $lastB
!ll&&!rl&&r
5710
MC/DC100%2/2
$ai <= $lastA and $bi <= $lastB
$ai <= $lastA $bi <= $lastB
Truth table100%3/3
A and B
A= $ai <= $lastAB= $bi <= $lastB
ABresult
0X0
100
111
392 {
393  
394 # Change
395 10 ▶ if ( defined $changeCallback )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $changeCallback) { } 10 0 10
396 {
397 10 &$changeCallback( $ai++, $bi++, @_ );
398 }
399 else
400 {
401 0 &$discardACallback( $ai++, $bi, @_ );
402 0 &$discardBCallback( $ai, $bi++, @_ );
403 }
404 }
405 elsif ( $ai <= $lastA )
406 {
407 7 &$discardACallback( $ai++, $bi, @_ );
408 }
409 else
410 {
411  
412 # $bi <= $lastB
413 5 &$discardBCallback( $ai, $bi++, @_ );
414 }
415 }
416  
417 20 return 1;
418 }
419  
420 sub prepare
421 {
422 0 ▶ my $a = shift; # array ref
Subroutine prepare: not called CC=2 SCAR=17.9
Pod documented
423 0 my $keyGen = shift; # code ref
424  
425 # set up code ref
426 0 ▶ $keyGen = sub { $_[0] } unless defined($keyGen);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keyGen 0 0 0
427  
428 0 return scalar _withPositionsOfInInterval( $a, 0, $#$a, $keyGen, @_ );
429 }
430  
431 sub LCS
432 {
433 1 ▶ my $a = shift; # array ref
Subroutine LCS: called CC=4 SCAR=13.9
Pod documented
434 1 my $b = shift; # array ref or hash ref
435 1 my $matchVector = _longestCommonSubsequence( $a, $b, 0, @_ );
436 1 my @retval;
437 my $i;
438 1 ▶ for ( $i = 0 ; $i <= $#$matchVector ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $matchVector->$#*) 8 1 9
439 {
440 8 ▶ if ( defined( $matchVector->[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $matchVector->[$i]) 6 2 8
441 {
442 6 push ( @retval, $a->[$i] );
443 }
444 }
445 1 ▶ return wantarray ? @retval : \@retval;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
446 }
447  
448 sub LCS_length
449 {
450 0 ▶ my $a = shift; # array ref
Subroutine LCS_length: not called CC=1 SCAR=6.9
Pod documented
451 0 my $b = shift; # array ref or hash ref
452 0 return _longestCommonSubsequence( $a, $b, 1, @_ );
453 }
454  
455 sub LCSidx
456 {
457 11 ▶ my $a= shift @_;
Subroutine LCSidx: called CC=1 SCAR=0.0
Pod documented
458 11 my $b= shift @_;
459 11 my $match= _longestCommonSubsequence( $a, $b, 0, @_ );
460 11 my @am= grep defined $match->[$_], 0..$#$match;
461 11 my @bm= @{$match}[@am];
462 11 return \@am, \@bm;
463 }
464  
465 sub compact_diff
466 {
467 11 ▶ my $a= shift @_;
Subroutine compact_diff: called CC=8 SCAR=20.8
Pod documented
468 11 my $b= shift @_;
469 11 my( $am, $bm )= LCSidx( $a, $b, @_ );
470 11 my @cdiff;
471 11 my( $ai, $bi )= ( 0, 0 );
472 11 push @cdiff, $ai, $bi;
473 11 while( 1 ) {
474 22 ▶ while( @$am && $ai == $am->[0] && $bi == $bm->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$am and $ai == $am->[0] and $bi == $bm->[0]) 22 22 44
Condition100%6/6
@$am and $ai == $am->[0] and $bi == $bm->[0]
!ll&&!rl&&r
16622
@$am and $ai == $am->[0]
!ll&&!rl&&r
11528
MC/DC100%3/3
@$am and $ai == $am->[0] and $bi == $bm->[0]
@$am $ai == $am->[0] $bi == $bm->[0]
Truth table100%4/4
A and B and C
A= @$amB= $ai == $am->[0]C= $bi == $bm->[0]
ABCresult
0XX0
10X0
1100
1111
475 22 shift @$am;
476 22 shift @$bm;
477 22 ++$ai, ++$bi;
478 }
479 22 push @cdiff, $ai, $bi;
480 22 ▶ last if ! @$am;
Branch: 1 branch
BranchTrueFalseTotal
unless @$am 11 11 22
481 11 $ai = $am->[0];
482 11 $bi = $bm->[0];
483 11 push @cdiff, $ai, $bi;
484 }
485 11 ▶ push @cdiff, 0+@$a, 0+@$b
Branch: 1 branch
BranchTrueFalseTotal
if $ai < @$a or $bi < @$b 7 4 11
Condition100%3/3
$ai < @$a or $bi < @$b
l!l&&r!l&&!r
524
MC/DC100%2/2
$ai < @$a or $bi < @$b
$ai < @$a $bi < @$b
Truth table100%3/3
A or B
A= $ai < @$aB= $bi < @$b
ABresult
1X1
011
000
486 if $ai < @$a || $bi < @$b;
487 11 ▶ return wantarray ? @cdiff : \@cdiff;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 11 11
488 }
489  
490 sub diff
491 {
492 1 ▶ my $a = shift; # array ref
Subroutine diff: called CC=2 SCAR=6.9
Pod documented
493 1 my $b = shift; # array ref
494 1 my $retval = [];
495 1 my $hunk = [];
496 my $discard = sub {
497 4 ▶ push @$hunk, [ '-', $_[0], $a->[ $_[0] ] ];
Subroutine __ANON__: called CC=1 SCAR=0.0
498 1 };
499 my $add = sub {
500 6 ▶ push @$hunk, [ '+', $_[1], $b->[ $_[1] ] ];
Subroutine __ANON__: called CC=1 SCAR=0.0
501 1 };
502 my $match = sub {
503 7 ▶ push @$retval, $hunk
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if 0 < @$hunk 5 2 7
504 if 0 < @$hunk;
505 7 $hunk = []
506 1 };
507 1 traverse_sequences( $a, $b,
508 { MATCH => $match, DISCARD_A => $discard, DISCARD_B => $add }, @_ );
509 1 &$match();
510 1 ▶ return wantarray ? @$retval : $retval;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
511 }
512  
513 sub sdiff
514 {
515 12 ▶ my $a = shift; # array ref
Subroutine sdiff: called CC=2 SCAR=6.9
Pod documented
516 12 my $b = shift; # array ref
517 12 my $retval = [];
518 12 ▶ my $discard = sub { push ( @$retval, [ '-', $a->[ $_[0] ], "" ] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
519 12 ▶ my $add = sub { push ( @$retval, [ '+', "", $b->[ $_[1] ] ] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
520 my $change = sub {
521 8 ▶ push ( @$retval, [ 'c', $a->[ $_[0] ], $b->[ $_[1] ] ] );
Subroutine __ANON__: called CC=1 SCAR=0.0
522 12 };
523 my $match = sub {
524 23 ▶ push ( @$retval, [ 'u', $a->[ $_[0] ], $b->[ $_[1] ] ] );
Subroutine __ANON__: called CC=1 SCAR=0.0
525 12 };
526 12 traverse_balanced(
527 $a,
528 $b,
529 {
530 MATCH => $match,
531 DISCARD_A => $discard,
532 DISCARD_B => $add,
533 CHANGE => $change,
534 },
535 @_
536 );
537 12 ▶ return wantarray ? @$retval : $retval;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 0 12
538 }
539  
540 ########################################
541 2 my $Root= __PACKAGE__;
542 package Algorithm::Diff::_impl;
543 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
544  
545 sub _Idx() { 0 } # $me->[_Idx]: Ref to array of hunk indices
546 # 1 # $me->[1]: Ref to first sequence
547 # 2 # $me->[2]: Ref to second sequence
548 sub _End() { 3 } # $me->[_End]: Diff between forward and reverse pos
549 sub _Same() { 4 } # $me->[_Same]: 1 if pos 1 contains unchanged items
550 sub _Base() { 5 } # $me->[_Base]: Added to range's min and max
551 sub _Pos() { 6 } # $me->[_Pos]: Which hunk is currently selected
552 sub _Off() { 7 } # $me->[_Off]: Offset into _Idx for current position
553 sub _Min() { -2 } # Added to _Off to get min instead of max+1
554  
555 sub Die
556 {
557 230 ▶ require Carp;
Subroutine Die: called CC=1 SCAR=0.0
558 230 Carp::confess( @_ );
559 }
560  
561 sub _ChkPos
562 {
563 1052 ▶ my( $me )= @_;
Subroutine _ChkPos: called CC=2 SCAR=6.9
564 1052 ▶ return if $me->[_Pos];
Branch: 1 branch
BranchTrueFalseTotal
if $me->[6] 942 110 1052
565 110 my $meth= ( caller(1) )[3];
566 110 Die( "Called $meth on 'reset' object" );
567 }
568  
569 sub _ChkSeq
570 {
571 650 ▶ my( $me, $seq )= @_;
Subroutine _ChkSeq: called CC=3 SCAR=11.0
572 650 ▶ return $seq + $me->[_Off]
Branch: 1 branch
BranchTrueFalseTotal
if 1 == $seq or 2 == $seq 540 110 650
Condition100%3/3
1 == $seq or 2 == $seq
l!l&&r!l&&!r
314226110
MC/DC100%2/2
1 == $seq or 2 == $seq
1 == $seq 2 == $seq
Truth table100%3/3
A or B
A= 1 == $seqB= 2 == $seq
ABresult
1X1
011
000
573 if 1 == $seq || 2 == $seq;
574 110 my $meth= ( caller(1) )[3];
575 110 Die( "$meth: Invalid sequence number ($seq); must be 1 or 2" );
576 }
577  
578 sub getObjPkg
579 {
580 13 ▶ my( $us )= @_;
Subroutine getObjPkg: called CC=2 SCAR=7.1
581 13 ▶ return ref $us if ref $us;
Branch: 1 branch
BranchTrueFalseTotal
if ref $us 0 13 13
582 13 return $us . "::_obj";
583 }
584  
585 sub new
586 {
587 11 ▶ my( $us, $seq1, $seq2, $opts ) = @_;
Subroutine new: called CC=7 SCAR=19.6
588 11 my @args;
589 11 for( $opts->{keyGen} ) {
590 11 ▶ push @args, $_ if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 11 11
591 }
592 11 for( $opts->{keyGenArgs} ) {
593 11 ▶ push @args, @$_ if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 11 11
594 }
595 11 my $cdif= Algorithm::Diff::compact_diff( $seq1, $seq2, @args );
596 11 my $same= 1;
597 11 ▶ if( 0 == $cdif->[2] && 0 == $cdif->[3] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == $cdif->[2] and 0 == $cdif->[3]) 8 3 11
Condition66%2/3
0 == $cdif->[2] and 0 == $cdif->[3]
!ll&&!rl&&r
308
MC/DC50%1/2
0 == $cdif->[2] and 0 == $cdif->[3]
0 == $cdif->[2] 0 == $cdif->[3]
Truth table66%2/3
A and B
A= 0 == $cdif->[2]B= 0 == $cdif->[3]
ABresult
0X0
100
111
598 8 $same= 0;
599 8 splice @$cdif, 0, 2;
600 }
601 11 my @obj= ( $cdif, $seq1, $seq2 );
602 11 $obj[_End] = (1+@$cdif)/2;
603 11 $obj[_Same] = $same;
604 11 $obj[_Base] = 0;
605 11 my $me = bless \@obj, $us->getObjPkg();
606 11 $me->Reset( 0 );
607 11 return $me;
608 }
609  
610 sub Reset
611 {
612 330 ▶ my( $me, $pos )= @_;
Subroutine Reset: called CC=6 SCAR=17.9
613 330 ▶ $pos= int( $pos || 0 );
Condition100%2/2
$pos || 0
l!l
25674
MC/DC100%1/1
$pos || 0
$pos
Truth table100%2/2
A
A= $pos
Aresult
11
00
614 330 ▶ $pos += $me->[_End]
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 82 248 330
615 if $pos < 0;
616 330 ▶ $pos= 0
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 or $me->[3] <= $pos 56 274 330
Condition100%3/3
$pos < 0 or $me->[3] <= $pos
l!l&&r!l&&!r
1244274
MC/DC100%2/2
$pos < 0 or $me->[3] <= $pos
$pos < 0 $me->[3] <= $pos
Truth table100%3/3
A or B
A= $pos < 0B= $me->[3] <= $pos
ABresult
1X1
011
000
617 if $pos < 0 || $me->[_End] <= $pos;
618 330 ▶ $me->[_Pos]= $pos || !1;
Condition100%2/2
$pos || !1
l!l
190140
MC/DC100%1/1
$pos || !1
$pos
Truth table100%2/2
A
A= $pos
Aresult
11
00
619 330 $me->[_Off]= 2*$pos - 1;
620 330 return $me;
621 }
622  
623 sub Base
624 {
625 162 ▶ my( $me, $base )= @_;
Subroutine Base: called CC=2 SCAR=6.9
626 162 my $oldBase= $me->[_Base];
627 162 ▶ $me->[_Base]= 0+$base if defined $base;
Branch: 1 branch
BranchTrueFalseTotal
if defined $base 43 119 162
628 162 return $oldBase;
629 }
630  
631 sub Copy
632 {
633 54 ▶ my( $me, $pos, $base )= @_;
Subroutine Copy: called CC=2 SCAR=6.9
634 54 my @obj= @$me;
635 54 my $you= bless \@obj, ref($me);
636 54 ▶ $you->Reset( $pos ) if defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos 11 43 54
637 54 $you->Base( $base );
638 54 return $you;
639 }
640  
641 sub Next {
642 347 ▶ my( $me, $steps )= @_;
Subroutine Next: called CC=5 SCAR=16.1
643 347 ▶ $steps= 1 if ! defined $steps;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $steps 110 237 347
644 347 ▶ if( $steps ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($steps) 242 105 347
645 242 my $pos= $me->[_Pos];
646 242 my $new= $pos + $steps;
647 242 ▶ $new= 0 if $pos && $new < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos and $new < 0 14 228 242
Condition100%3/3
$pos and $new < 0
!ll&&!rl&&r
10812014
MC/DC100%2/2
$pos and $new < 0
$pos $new < 0
Truth table100%3/3
A and B
A= $posB= $new < 0
ABresult
0X0
100
111
648 242 $me->Reset( $new )
649 }
650 347 return $me->[_Pos];
651 }
652  
653 sub Prev {
654 109 ▶ my( $me, $steps )= @_;
Subroutine Prev: called CC=3 SCAR=11.0
655 109 ▶ $steps= 1 if ! defined $steps;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $steps 53 56 109
656 109 my $pos= $me->Next(-$steps);
657 109 ▶ $pos -= $me->[_End] if $pos;
Branch: 1 branch
BranchTrueFalseTotal
if $pos 54 55 109
658 109 return $pos;
659 }
660  
661 sub Diff {
662 81 ▶ my( $me )= @_;
Subroutine Diff: called CC=4 SCAR=13.9
663 81 $me->_ChkPos();
664 70 ▶ return 0 if $me->[_Same] == ( 1 & $me->[_Pos] );
Branch: 1 branch
BranchTrueFalseTotal
if $me->[4] == (1 & $me->[6]) 20 50 70
665 50 my $ret= 0;
666 50 my $off= $me->[_Off];
667 50 for my $seq ( 1, 2 ) {
668 100 ▶ $ret |= $seq
Branch: 1 branch
BranchTrueFalseTotal
if $me->[0][$off + $seq + -2] < $me->[0][$off + $seq] 66 34 100
669 if $me->[_Idx][ $off + $seq + _Min ]
670 < $me->[_Idx][ $off + $seq ];
671 }
672 50 return $ret;
673 }
674  
675 sub Min {
676 91 ▶ my( $me, $seq, $base )= @_;
Subroutine Min: called CC=2 SCAR=6.9
677 91 $me->_ChkPos();
678 80 my $off= $me->_ChkSeq($seq);
679 50 ▶ $base= $me->[_Base] if !defined $base;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base 40 10 50
680 50 return $base + $me->[_Idx][ $off + _Min ];
681 }
682  
683 sub Max {
684 91 ▶ my( $me, $seq, $base )= @_;
Subroutine Max: called CC=2 SCAR=6.9
685 91 $me->_ChkPos();
686 80 my $off= $me->_ChkSeq($seq);
687 50 ▶ $base= $me->[_Base] if !defined $base;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base 10 40 50
688 50 return $base + $me->[_Idx][ $off ] -1;
689 }
690  
691 sub Range {
692 295 ▶ my( $me, $seq, $base )= @_;
Subroutine Range: called CC=3 SCAR=11.0
693 295 $me->_ChkPos();
694 284 my $off = $me->_ChkSeq($seq);
695 254 ▶ if( !wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 104 150 254
696 104 return $me->[_Idx][ $off ]
697 - $me->[_Idx][ $off + _Min ];
698 }
699 150 ▶ $base= $me->[_Base] if !defined $base;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base 98 52 150
700 150 return ( $base + $me->[_Idx][ $off + _Min ] )
701 .. ( $base + $me->[_Idx][ $off ] - 1 );
702 }
703  
704 sub Items {
705 217 ▶ my( $me, $seq )= @_;
Subroutine Items: called CC=2 SCAR=6.9
706 217 $me->_ChkPos();
707 206 my $off = $me->_ChkSeq($seq);
708 186 ▶ if( !wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 48 138 186
709 48 return $me->[_Idx][ $off ]
710 - $me->[_Idx][ $off + _Min ];
711 }
712 return
713 138 @{$me->[$seq]}[
714 $me->[_Idx][ $off + _Min ]
715 .. ( $me->[_Idx][ $off ] - 1 )
716 ];
717 }
718  
719 sub Same {
720 156 ▶ my( $me )= @_;
Subroutine Same: called CC=3 SCAR=11.0
721 156 $me->_ChkPos();
722 112 ▶ return wantarray ? () : 0
Branch: 2 branches
BranchTrueFalseTotal
if $me->[4] != (1 & $me->[6]) 50 62 112
wantarray ? : 0 50 50
723 if $me->[_Same] != ( 1 & $me->[_Pos] );
724 62 return $me->Items(1);
725 }
726  
727 2 my %getName;
728 BEGIN {
729 2 ▶ %getName= (
Subroutine BEGIN: called CC=1 SCAR=0.0
730 same => \&Same,
731 diff => \&Diff,
732 base => \&Base,
733 min => \&Min,
734 max => \&Max,
735 range=> \&Range,
736 items=> \&Items, # same thing
737 );
738 }
739  
740 sub Get
741 {
742 121 ▶ my $me= shift @_;
Subroutine Get: called CC=8 SCAR=21.1
743 121 $me->_ChkPos();
744 110 my @value;
745 110 for my $arg ( @_ ) {
746 130 for my $word ( split ' ', $arg ) {
747 160 my $meth;
748 160 ▶ if( $word !~ /^(-?\d+)?([a-zA-Z]+)([12])?$/
Branch: 1 branch
BranchTrueFalseTotal
unless ($word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ and $meth = $getName{lc $2}) 0 160 160
Condition33%1/3
$word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ and $meth = $getName{lc $2}
!ll&&!rl&&r
00160
MC/DC0%0/2
$word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ and $meth = $getName{lc $2}
$word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ $meth = $getName{lc $2}
Truth table33%1/3
A and B
A= $word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/B= $meth = $getName{lc $2}
ABresult
0X0
100
111
749 || not $meth= $getName{ lc $2 }
750 ) {
751 0 Die( $Root, ", Get: Invalid request ($word)" );
752 }
753 160 my( $base, $name, $seq )= ( $1, $2, $3 );
754 160 ▶ push @value, scalar(
Branch: 1 branch
BranchTrueFalseTotal
4 == length $name ? : 30 130 160
755 4 == length($name)
756 ? $meth->( $me )
757 : $meth->( $me, $seq, $base )
758 );
759 }
760 }
761 80 ▶ if( wantarray ) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 30 50 80
elsif (1 == @value) { } 40 10 50
762 30 return @value;
763 } elsif( 1 == @value ) {
764 40 return $value[0];
765 }
766 10 Die( 0+@value, " values requested from ",
767 $Root, "'s Get in scalar context" );
768 }
769  
770  
771 2 my $Obj= getObjPkg($Root);
772 2 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
773  
774 2 for my $meth ( qw( new getObjPkg ) ) {
775 4 *{$Root."::".$meth} = \&{$meth};
776 4 *{$Obj ."::".$meth} = \&{$meth};
777 }
778 2 for my $meth ( qw(
779 Next Prev Reset Copy Base Diff
780 Same Items Range Min Max Get
781 _ChkPos _ChkSeq
782 ) ) {
783 28 *{$Obj."::".$meth} = \&{$meth};
784 }
785  
786 2 1;
787 __END__
« blib/lib/Algorithm/DiffOld.pm ↑ Summary blib/lib/Algorithm/diff.pl »