| 1 | package Algorithm::CheckDigits::M09_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 | |||||||||||||||||||||
| 7 | 2 | ▶ | use version; our $VERSION = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||
| 12 | 2 | my $proto = shift; | |||||||||||||||||||
| 13 | 2 | ▶ | 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
| |||||||||||||||||||||
| 14 | 2 | return bless({}, $class); | |||||||||||||||||||
| 15 | } # new() | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 4 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 18 | 4 | my ($self,$number) = @_; | |||||||||||||||||||
| 19 | 4 | ▶ | if ($number =~ /^([A-Za-z][0-9]{10})([0-9])$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 4 | return $2 == _compute_checkdigit($1); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | 0 | return 0; | |||||||||||||||||||
| 23 | } # is_valid() | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 2 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 26 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 27 | 2 | ▶ | if ($number =~ /^[A-Za-z][0-9]{10}$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 2 | return $number . _compute_checkdigit($number); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | 0 | return ''; | |||||||||||||||||||
| 31 | } # complete() | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 2 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 34 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 35 | 2 | ▶ | if ($number =~ /^([A-Za-z][0-9]{10})([0-9])$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 2 | ▶ | return $1 if ($2 == _compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 0 | return ''; | |||||||||||||||||||
| 39 | } # basenumber() | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 2 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 42 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 43 | 2 | ▶ | if ($number =~ /^([A-Za-z][0-9]{10})([0-9])$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 2 | ▶ | return $2 if ($2 == _compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | return ''; | |||||||||||||||||||
| 47 | } # checkdigit() | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 10 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 50 | 10 | my $number = shift; | |||||||||||||||||||
| 51 | 10 | ▶ | if ($number =~ /^([A-Za-z])([0-9]{10})$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 10 | my @nums = (); | |||||||||||||||||||
| 53 | 10 | my $sum = 0; | |||||||||||||||||||
| 54 | 10 | push(@nums,ord(uc($1)) - ord('A') +1); | |||||||||||||||||||
| 55 | 10 | push(@nums,split(//,$2)); | |||||||||||||||||||
| 56 | 10 | foreach my $num (@nums) { | |||||||||||||||||||
| 57 | 110 | $sum += $num; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 10 | return 8 - ($sum % 9); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | 0 | return -1; | |||||||||||||||||||
| 62 | } # _compute_checkdigit() | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # Preloaded methods go here. | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 2 | 1; | |||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||