| 1 | package Algorithm::CheckDigits::M11_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 @weight = ( 5, 4, 3, 2, 7, 6, 5, 4, 3, 2 ); | |||||||||||||||||||
| 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 =~ /^([0-9.]+)(\d)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 2 | return $2 == $self->_compute_checkdigits($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 =~ /^([0-9.]+)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 1 | return "$1" . $self->_compute_checkdigits($1); | |||||||||||||||||||
| 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 =~ /^([0-9.]+)(\d)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 1 | ▶ | return $1 if ($2 == $self->_compute_checkdigits($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 =~ /^([0-9.]+)(\d)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 1 | ▶ | return $2 if ($2 == $self->_compute_checkdigits($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 0 | return ''; | |||||||||||||||||||
| 53 | } # checkdigit() | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 5 | ▶ | sub _compute_checkdigits { | ||||||||||||||||||
|
Subroutine
_compute_checkdigits: called CC=4 SCAR=14.0
| |||||||||||||||||||||
| 56 | 5 | my $self = shift; | |||||||||||||||||||
| 57 | 5 | my $number = shift; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 5 | $number =~ s/\.//g; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 5 | my @digits = split(//,$number); | |||||||||||||||||||
| 62 | 5 | my $sum = 0; | |||||||||||||||||||
| 63 | 5 | ▶ | for (my $i = 0; $i <= $#digits; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 50 | $sum += $weight[$i] * $digits[$i]; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | 5 | $sum %= 11; | |||||||||||||||||||
| 67 | 5 | ▶ | return $sum == 0 ? 0 : ($sum == 1 ? '' : 11 - $sum); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 68 | } # _compute_checkdigit() | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | # Preloaded methods go here. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||