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