| 1 | package Algorithm::CheckDigits::MXX_005; | ||||||||||||||||||||
| 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 = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | my $ctable = [ | |||||||||||||||||||
| 13 | [ 0, 9, 4, 6, 8, 2, 7, 1, 3, 5, 0, ], | ||||||||||||||||||||
| 14 | [ 9, 4, 6, 8, 2, 7, 1, 3, 5, 0, 9, ], | ||||||||||||||||||||
| 15 | [ 4, 6, 8, 2, 7, 1, 3, 5, 0, 9, 8, ], | ||||||||||||||||||||
| 16 | [ 6, 8, 2, 7, 1, 3, 5, 0, 9, 4, 7, ], | ||||||||||||||||||||
| 17 | [ 8, 2, 7, 1, 3, 5, 0, 9, 4, 6, 6, ], | ||||||||||||||||||||
| 18 | [ 2, 7, 1, 3, 5, 0, 9, 4, 6, 8, 5, ], | ||||||||||||||||||||
| 19 | [ 7, 1, 3, 5, 0, 9, 4, 6, 8, 2, 4, ], | ||||||||||||||||||||
| 20 | [ 1, 3, 5, 0, 9, 4, 6, 8, 2, 7, 3, ], | ||||||||||||||||||||
| 21 | [ 3, 5, 0, 9, 4, 6, 8, 2, 7, 1, 2, ], | ||||||||||||||||||||
| 22 | [ 5, 0, 9, 4, 6, 8, 2, 7, 1, 3, 1, ], | ||||||||||||||||||||
| 23 | ]; | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 26 | 1 | my $proto = shift; | |||||||||||||||||||
| 27 | 1 | my $type = shift; | |||||||||||||||||||
| 28 | 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
| |||||||||||||||||||||
| 29 | 1 | my $self = bless({}, $class); | |||||||||||||||||||
| 30 | 1 | $self->{type} = lc($type); | |||||||||||||||||||
| 31 | 1 | return $self; | |||||||||||||||||||
| 32 | } # new() | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 2 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 35 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 36 | 2 | ▶ | if ($number =~ /^(\d{8})(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 2 | return $2 == $self->_compute_checkdigit($1); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | 0 | return '' | |||||||||||||||||||
| 40 | } # is_valid() | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 43 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 44 | 1 | ▶ | if ($number =~ /^(\d{8})$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 1 | return $number . $self->_compute_checkdigit($1); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | 0 | return ''; | |||||||||||||||||||
| 48 | } # complete() | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 51 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 52 | 1 | ▶ | if ($number =~ /^(\d{8})(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 1 | ▶ | return $1 if ($2 == $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | return ''; | |||||||||||||||||||
| 56 | } # basenumber() | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 59 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 60 | 1 | ▶ | if ($number =~ /^(\d{8})(\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 1 | ▶ | return $2 if ($2 == $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 0 | return ''; | |||||||||||||||||||
| 64 | } # checkdigit() | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 5 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 67 | 5 | my $self = shift; | |||||||||||||||||||
| 68 | 5 | my $number = shift; | |||||||||||||||||||
| 69 | 5 | my $carry = 0; | |||||||||||||||||||
| 70 | 5 | ▶ | if ($number =~ /^\d{8}$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 5 | my @digits = split(//,$number); | |||||||||||||||||||
| 72 | 5 | ▶ | for (my $i = 0;$i <= $#digits;$i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 40 | $carry = $ctable->[$carry]->[$digits[$i]]; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 5 | return (10 - $carry) % 10; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | 0 | return -1; | |||||||||||||||||||
| 78 | } # _compute_checkdigit() | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | # Preloaded methods go here. | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2 | 1; | |||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||