| 1 | package Algorithm::CheckDigits::M23_001; | ||||||||||||||||||||
| 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 @keytable = ( | |||||||||||||||||||
| 13 | 'T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', | ||||||||||||||||||||
| 14 | 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', | ||||||||||||||||||||
| 15 | 'Q', 'V', 'H', 'L', 'C', 'K', 'E', | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 19 | 1 | my $proto = shift; | |||||||||||||||||||
| 20 | 1 | my $type = shift; | |||||||||||||||||||
| 21 | 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
| |||||||||||||||||||||
| 22 | 1 | my $self = bless({}, $class); | |||||||||||||||||||
| 23 | 1 | $self->{type} = lc($type); | |||||||||||||||||||
| 24 | 1 | return $self; | |||||||||||||||||||
| 25 | } # new() | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 2 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 28 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 29 | 2 | ▶ | if ($number =~ /^(\d{8})-?([A-HJ-NP-TV-Z])$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 2 | return $2 eq $self->_compute_checkdigit($1); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | 0 | return '' | |||||||||||||||||||
| 33 | } # is_valid() | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 1 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 36 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 37 | 1 | ▶ | if ($number =~ /^(\d{8})-?$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 1 | return $number . $self->_compute_checkdigit($1); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | 0 | return ''; | |||||||||||||||||||
| 41 | } # complete() | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 44 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 45 | 1 | ▶ | if ($number =~ /^(\d{8}-?)([A-HJ-NP-TV-Z])$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 1 | ▶ | return $1 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 0 | return ''; | |||||||||||||||||||
| 49 | } # basenumber() | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 52 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 53 | 1 | ▶ | if ($number =~ /^(\d{8})-?([A-HJ-NP-TV-Z])$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 1 | ▶ | return $2 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 0 | return ''; | |||||||||||||||||||
| 57 | } # checkdigit() | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 5 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 60 | 5 | my $self = shift; | |||||||||||||||||||
| 61 | 5 | my $number = shift; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 5 | $number =~ s/-//g; | |||||||||||||||||||
| 64 | 5 | ▶ | if ($number =~ /^\d{8}$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 5 | return $keytable[($number % 23)]; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 0 | return -1; | |||||||||||||||||||
| 68 | } # _compute_checkdigit() | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | # Preloaded methods go here. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||