| 1 | package Algorithm::CheckDigits::MXX_003; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use integer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use version; our $VERSION = qv('v1.3.6'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | my $perm = [ | |||||||||||||||||||
| 13 | [ 1, 5, 7, 6, 2, 8, 3, 0, 9, 4, ], | ||||||||||||||||||||
| 14 | [ 5, 8, 0, 3, 7, 9, 6, 1, 4, 2, ], | ||||||||||||||||||||
| 15 | [ 8, 9, 1, 6, 0, 4, 3, 5, 2, 7, ], | ||||||||||||||||||||
| 16 | [ 9, 4, 5, 3, 1, 2, 6, 8, 7, 0, ], | ||||||||||||||||||||
| 17 | [ 4, 2, 8, 6, 5, 7, 3, 9, 0, 1, ], | ||||||||||||||||||||
| 18 | [ 2, 7, 9, 3, 8, 0, 6, 4, 1, 5, ], | ||||||||||||||||||||
| 19 | [ 7, 0, 4, 6, 9, 1, 3, 2, 5, 8, ], | ||||||||||||||||||||
| 20 | [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ], | ||||||||||||||||||||
| 21 | [ 1, 5, 7, 6, 2, 8, 3, 0, 9, 4, ], | ||||||||||||||||||||
| 22 | [ 5, 8, 0, 3, 7, 9, 6, 1, 4, 2, ], | ||||||||||||||||||||
| 23 | [ 8, 9, 1, 6, 0, 4, 3, 5, 2, 7, ], | ||||||||||||||||||||
| 24 | ]; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | my $dieder = [ | |||||||||||||||||||
| 27 | [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ], | ||||||||||||||||||||
| 28 | [ 1, 2, 3, 4, 0, 6, 7, 8, 9, 5, ], | ||||||||||||||||||||
| 29 | [ 2, 3, 4, 0, 1, 7, 8, 9, 5, 6, ], | ||||||||||||||||||||
| 30 | [ 3, 4, 0, 1, 2, 8, 9, 5, 6, 7, ], | ||||||||||||||||||||
| 31 | [ 4, 0, 1, 2, 3, 9, 5, 6, 7, 8, ], | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | [ 5, 9, 8, 7, 6, 0, 4, 3, 2, 1, ], | ||||||||||||||||||||
| 34 | [ 6, 5, 9, 8, 7, 1, 0, 4, 3, 2, ], | ||||||||||||||||||||
| 35 | [ 7, 6, 5, 6, 8, 2, 1, 0, 4, 3, ], | ||||||||||||||||||||
| 36 | [ 8, 7, 6, 5, 9, 3, 2, 1, 0, 4, ], | ||||||||||||||||||||
| 37 | [ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ], | ||||||||||||||||||||
| 38 | ]; | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 41 | 1 | my $proto = shift; | |||||||||||||||||||
| 42 | 1 | my $type = shift; | |||||||||||||||||||
| 43 | 1 | ▶ | 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
| |||||||||||||||||||||
| 44 | 1 | my $self = bless({}, $class); | |||||||||||||||||||
| 45 | 1 | $self->{type} = lc($type); | |||||||||||||||||||
| 46 | 1 | return $self; | |||||||||||||||||||
| 47 | } # new() | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 50 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 51 | 2 | ▶ | if ($number =~ /^([ADGKLNSUYZ]{2}\d{7}[ADGKLNSUYZ])(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 2 | ▶ | return 1 if ($2 == $self->_compute_checkdigit(uc($1))); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 1 | return '' | |||||||||||||||||||
| 55 | } # is_valid() | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 58 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 59 | 1 | ▶ | if ($number =~ /^[ADGKLNSUYZ]{2}\d{7}[ADGKLNSUYZ]$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 1 | return $number . $self->_compute_checkdigit(uc($number)); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | return ''; | |||||||||||||||||||
| 63 | } # complete() | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 1 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 66 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 67 | 1 | ▶ | if ($number =~ /^([ADGKLNSUYZ]{2}\d{7}[ADGKLNSUYZ])(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 1 | ▶ | return $1 if ($2 == $self->_compute_checkdigit(uc($1))); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 0 | return ''; | |||||||||||||||||||
| 71 | } # basenumber() | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 74 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 75 | 1 | ▶ | if ($number =~ /^([ADGKLNSUYZ]{2}\d{7}[ADGKLNSUYZ])(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 1 | ▶ | return $2 if ($2 == $self->_compute_checkdigit(uc($1))); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | 0 | return ''; | |||||||||||||||||||
| 79 | } # checkdigit() | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 5 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 82 | 5 | my $self = shift; | |||||||||||||||||||
| 83 | 5 | my $number = shift; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 5 | $number =~ tr/ADGKLNSUYZ/0-9/; | |||||||||||||||||||
| 86 | 5 | my @digits = split(//,$number); | |||||||||||||||||||
| 87 | 5 | my $p0 = $perm->[0]->[$digits[0]]; | |||||||||||||||||||
| 88 | 5 | my $rd = $p0; | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 5 | ▶ | for (my $i = 1; $i <= $#digits; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 45 | my $pi = $perm->[$i % 8]->[$digits[$i]]; | |||||||||||||||||||
| 92 | 45 | $rd = $dieder->[$rd]->[$pi]; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | 5 | ▶ | for (my $j = 0; $j <= 9; $j++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 10 | ▶ | return $j unless($dieder->[$rd]->[$j]); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | return -1; | |||||||||||||||||||
| 99 | } # _compute_checkdigit() | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | # Preloaded methods go here. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||