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