| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 38 | 6 | ▶ | return $1 . $self->_compute_checkdigit($1,$2) . ($2 || ''); | ||||||||||||||||||||||||||
|
Condition100%2/2
$2 || ''
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 6 | ▶ | if (uc($2) eq $self->_compute_checkdigit($1,$3)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 6 | ▶ | return $3 ? "$1.$3" : $1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 56 | 6 | ▶ | return $2 if (uc($2) eq $self->_compute_checkdigit($1,$3)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | 294 | $sum += $digits[$i] * (8-$i); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 42 | ▶ | if ($optional and $optional =~ /[A-I]/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$optional and $optional =~ /[A-I]/i
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||