| 1 | package Algorithm::CheckDigits::MXX_006; | ||||||||||||||||||||
| 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 Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use version; our $VERSION = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | our @inverted = (0, 4, 3, 2, 1, 5, 6, 7, 8, 9 ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | my $perm = [ | |||||||||||||||||||
| 17 | [ 1, 5, 7, 6, 2, 8, 3, 0, 9, 4, ], | ||||||||||||||||||||
| 18 | [ 5, 8, 0, 3, 7, 9, 6, 1, 4, 2, ], | ||||||||||||||||||||
| 19 | [ 8, 9, 1, 6, 0, 4, 3, 5, 2, 7, ], | ||||||||||||||||||||
| 20 | [ 9, 4, 5, 3, 1, 2, 6, 8, 7, 0, ], | ||||||||||||||||||||
| 21 | [ 4, 2, 8, 6, 5, 7, 3, 9, 0, 1, ], | ||||||||||||||||||||
| 22 | [ 2, 7, 9, 3, 8, 0, 6, 4, 1, 5, ], | ||||||||||||||||||||
| 23 | [ 7, 0, 4, 6, 9, 1, 3, 2, 5, 8, ], | ||||||||||||||||||||
| 24 | [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ], | ||||||||||||||||||||
| 25 | [ 1, 5, 7, 6, 2, 8, 3, 0, 9, 4, ], | ||||||||||||||||||||
| 26 | [ 5, 8, 0, 3, 7, 9, 6, 1, 4, 2, ], | ||||||||||||||||||||
| 27 | [ 8, 9, 1, 6, 0, 4, 3, 5, 2, 7, ], | ||||||||||||||||||||
| 28 | ]; | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 2 | my $dieder = [ | |||||||||||||||||||
| 31 | [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ], | ||||||||||||||||||||
| 32 | [ 1, 2, 3, 4, 0, 6, 7, 8, 9, 5, ], | ||||||||||||||||||||
| 33 | [ 2, 3, 4, 0, 1, 7, 8, 9, 5, 6, ], | ||||||||||||||||||||
| 34 | [ 3, 4, 0, 1, 2, 8, 9, 5, 6, 7, ], | ||||||||||||||||||||
| 35 | [ 4, 0, 1, 2, 3, 9, 5, 6, 7, 8, ], | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | [ 5, 9, 8, 7, 6, 0, 4, 3, 2, 1, ], | ||||||||||||||||||||
| 38 | [ 6, 5, 9, 8, 7, 1, 0, 4, 3, 2, ], | ||||||||||||||||||||
| 39 | [ 7, 6, 5, 6, 8, 2, 1, 0, 4, 3, ], | ||||||||||||||||||||
| 40 | [ 8, 7, 6, 5, 9, 3, 2, 1, 0, 4, ], | ||||||||||||||||||||
| 41 | [ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ], | ||||||||||||||||||||
| 42 | ]; | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 45 | 1 | my $proto = shift; | |||||||||||||||||||
| 46 | 1 | my $type = shift; | |||||||||||||||||||
| 47 | 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
| |||||||||||||||||||||
| 48 | 1 | my $self = bless({}, $class); | |||||||||||||||||||
| 49 | 1 | $self->{type} = lc($type); | |||||||||||||||||||
| 50 | 1 | return $self; | |||||||||||||||||||
| 51 | } # new() | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 2 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 54 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 55 | 2 | ▶ | if ($number =~ /^(\d+)(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 2 | ▶ | return 1 if ($2 == $self->_compute_checkdigit(uc($1))); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | 1 | return '' | |||||||||||||||||||
| 59 | } # is_valid() | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 62 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 63 | 1 | ▶ | if ($number =~ /^\d+$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 1 | return $number . $self->_compute_checkdigit(uc($number)); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | 0 | return ''; | |||||||||||||||||||
| 67 | } # complete() | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 70 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 71 | 1 | ▶ | if ($number =~ /^(\d+)(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 1 | ▶ | return $1 if ($2 == $self->_compute_checkdigit(uc($1))); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | return ''; | |||||||||||||||||||
| 75 | } # basenumber() | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 78 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 79 | 1 | ▶ | if ($number =~ /^(\d+)(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 1 | ▶ | return $2 if ($2 == $self->_compute_checkdigit(uc($1))); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | return ''; | |||||||||||||||||||
| 83 | } # checkdigit() | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 5 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 86 | 5 | my $self = shift; | |||||||||||||||||||
| 87 | 5 | my $number = shift; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 5 | my $input = shift; | |||||||||||||||||||
| 90 | 5 | my $c = 0; # initialize check at 0 | |||||||||||||||||||
| 91 | 5 | my $digit = 0; | |||||||||||||||||||
| 92 | 5 | my $i = 0; my $r; | |||||||||||||||||||
| 93 | 5 | foreach $digit (reverse split(//, $number)) { | |||||||||||||||||||
| 94 | # This was jonathans implementation, his permutation | ||||||||||||||||||||
| 95 | # table is offset by one compared to the one I already | ||||||||||||||||||||
| 96 | # took in MXX_003.pm and reused here | ||||||||||||||||||||
| 97 | # $c = $di->[$c]->[$f->[($i+1) % 8]->[$digit]]; | ||||||||||||||||||||
| 98 | 35 | $c = $dieder->[$c]->[$perm->[$i % 8]->[$digit]]; | |||||||||||||||||||
| 99 | 35 | $i++; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | 5 | return $inverted[$c]; | |||||||||||||||||||
| 102 | } # _compute_checkdigit() | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | # Preloaded methods go here. | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 2 | 1; | |||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||