blib/lib/Algorithm/CheckDigits/M23_002.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 66.6% 12 / 18 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 84.3% 81 / 96 CC 13 SCAR 10.6
CC
13
Cov
84%
basenumber
4.3
_compute_checkdigit
4.0
checkdigit
3.5
CRAP 2.9
« blib/lib/Algorithm/CheckDigits/M11_001.pm ↑ Summary blib/lib/Algorithm/CheckDigits/MBase_003.pm »
1 package Algorithm::CheckDigits::M23_002;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use version; our $VERSION = 'v1.3.6';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our @ISA = qw(Algorithm::CheckDigits);
11  
12 3 my @keytable = (
13 'W', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
14 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
15 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
16 );
17  
18 7 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
19 7 my $proto = shift;
20 7 my $type = shift;
21 7 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
070
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
22 7 my $self = bless({}, $class);
23 7 $self->{type} = lc($type);
24 7 return $self;
25 } # new()
26  
27 24 ▶sub is_valid {
Subroutine is_valid: called CC=2 SCAR=7.6
Pod documented
28 24 my ($self,$number) = @_;
29 24 ▶ if ($number =~ /^(\d{7})([A-W])([A-IW])?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^(\d{7})([A-W])([A-IW])?$/i) 24 0 24
30 24 return $2 eq $self->_compute_checkdigit($1,$3);
31 }
32 0 return ''
33 } # is_valid()
34  
35 6 ▶sub complete {
Subroutine complete: called CC=3 SCAR=11.4
Pod documented
36 6 my ($self,$number) = @_;
37 6 ▶ if ($number =~ /^(\d{7}).?([A-IW])?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^(\d{7}).?([A-IW])?$/i) 6 0 6
38 6 ▶ return $1 . $self->_compute_checkdigit($1,$2) . ($2 || '');
Condition100%2/2
$2 || ''
l!l
33
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
39 }
40 0 return '';
41 } # complete()
42  
43 6 ▶sub basenumber {
Subroutine basenumber: called CC=4 SCAR=14.6
Pod documented
44 6 my ($self,$number) = @_;
45 6 ▶ if ($number =~ /^(\d{7})([A-W])([A-IW])?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^(\d{7})([A-W])([A-IW])?$/i) 6 0 6
46 6 ▶ if (uc($2) eq $self->_compute_checkdigit($1,$3)) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $2 eq $self->_compute_checkdigit($1, $3)) 6 0 6
47 6 ▶ return $3 ? "$1.$3" : $1;
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 3 3 6
48 }
49 }
50 0 return '';
51 } # basenumber()
52  
53 6 ▶sub checkdigit {
Subroutine checkdigit: called CC=3 SCAR=12.5
Pod documented
54 6 my ($self,$number) = @_;
55 6 ▶ if ($number =~ /^(\d{7})([A-W])([A-IW])?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^(\d{7})([A-W])([A-IW])?$/i) 6 0 6
56 6 ▶ return $2 if (uc($2) eq $self->_compute_checkdigit($1,$3));
Branch: 1 branch
BranchTrueFalseTotal
if uc $2 eq $self->_compute_checkdigit($1, $3) 6 0 6
57 }
58 0 return '';
59 } # checkdigit()
60  
61 42 ▶sub _compute_checkdigit {
Subroutine _compute_checkdigit: called CC=4 SCAR=13.9
62 42 my ($self, $number,$optional) = @_;
63 42 my $sum = 0;
64 42 my @digits = split(//,$number);
65  
66 42 ▶ for (my $i = 0; $i < 7; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 7) 294 42 336
67 294 $sum += $digits[$i] * (8-$i);
68 }
69 42 ▶ if ($optional and $optional =~ /[A-I]/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($optional and $optional =~ /[A-I]/i) 7 35 42
Condition100%3/3
$optional and $optional =~ /[A-I]/i
!ll&&!rl&&r
21147
MC/DC100%2/2
$optional and $optional =~ /[A-I]/i
$optional $optional =~ /[A-I]/i
Truth table100%3/3
A and B
A= $optionalB= $optional =~ /[A-I]/i
ABresult
0X0
100
111
70 7 $sum += 9 * (ord($optional) - ord('A') + 1);
71 }
72 42 return $keytable[$sum % 23];
73  
74 } # _compute_checkdigit()
75  
76 # Preloaded methods go here.
77  
78 3 1;
79 __END__
« blib/lib/Algorithm/CheckDigits/M11_001.pm ↑ Summary blib/lib/Algorithm/CheckDigits/MBase_003.pm »