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