Utils/Array.pm

filter: Statementstmt 70.0% 21 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 57.1% 28 / 49 CC 6 SCAR 27.0
CC
6
Cov
54%
array1_starts_with_array2
28.7
BEGIN
1.0
BEGIN
1.0
CRAP 14.8
« Utils/General.pm ↑ Summary Utils/Hash.pm »
1 #===============================================
2 package Banal::Utils::Array;
3  
4 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 require Exporter;
11  
12 2 our @ISA = qw(Exporter);
13 2 our @EXPORT_OK = qw(array1_starts_with_array2);
14  
15 # Returns true (1) if array1 starts with array2 (via element-by-element equality), false (0) otherwise.
16 # The order of elements is important (it ain't a bag). For each compared element, equality can be established either thru string (eq) or numeric (==) comparison.
17 0 ▶sub array1_starts_with_array2 {
Subroutine array1_starts_with_array2: not called CC=6 SCAR=33.6
Pod documented
18 0 my ($array1, $array2) = @_;
19  
20 # if array2 is empty, then the result is undefined.
21 0 ▶ return unless (scalar($array2));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $array2 0 0 0
22
23 # if array2 has more items than array1, then array1 can't possibly start with array2.
24 0 ▶ return 0 if (scalar($array2) > scalar($array1));
Branch: 1 branch
BranchTrueFalseTotal
if scalar $array2 > scalar $array1 0 0 0
25
26 0 my $k = 0;
27 0 foreach my $e2 (@$array2) {
28 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 0 my $e1 = $array1->[$k];
30
31 # Here, we allow both string and numeric equality. It's kind o a relaxed thing. The "no warnings" pragma (above) comes in handy.
32 0 ▶ return 0 unless (($e1 eq $e2) || ($e1 == $e2));
Branch: 1 branch
BranchTrueFalseTotal
unless $e1 eq $e2 or $e1 == $e2 0 0 0
Condition0%0/3
$e1 eq $e2 or $e1 == $e2
l!l&&r!l&&!r
000
MC/DC0%0/2
$e1 eq $e2 or $e1 == $e2
$e1 eq $e2 $e1 == $e2
Truth table0%0/3
A or B
A= $e1 eq $e2B= $e1 == $e2
ABresult
1X1
011
000
33 0 $k++;
34 }
35 0 return 1;
36 }
37  
38  
39  
40  
41 2 1;
42  
43 __END__
« Utils/General.pm ↑ Summary Utils/Hash.pm »