| 1 | package Algorithm::CheckDigits::M11_011; | ||||||||||||||||||||||||||||
| 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 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my $proto = shift; | |||||||||||||||||||||||||||
| 14 | 2 | my $type = shift; | |||||||||||||||||||||||||||
| 15 | 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
| |||||||||||||||||||||||||||||
| 16 | 2 | my $self = bless({}, $class); | |||||||||||||||||||||||||||
| 17 | 2 | $self->{type} = lc($type); | |||||||||||||||||||||||||||
| 18 | 2 | return $self; | |||||||||||||||||||||||||||
| 19 | } # new() | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub is_valid { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 4 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 23 | 4 | ▶ | if ($number =~ /^([0-9]+)(\d)(B\d\d)?$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 4 | return $2 == $self->_compute_checkdigits($1); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 0 | return '' | |||||||||||||||||||||||||||
| 27 | } # is_valid() | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub complete { | ||||||||||||||||||||||||||
|
Subroutine
complete: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 2 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 31 | 2 | ▶ | if ($number =~ /^([0-9]+)(?:.(B\d\d))?$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$number =~ /^([0-9]+)(?:.(B\d\d))?$/ and (my $cd = $self->_compute_checkdigits($1)) ne ""
MC/DC0%0/2
$number =~ /^([0-9]+)(?:.(B\d\d))?$/ and (my $cd = $self->_compute_checkdigits($1)) ne ""
$number =~ /^([0-9]+)(?:.(B\d\d))?$/
(my $cd = $self->_compute_checkdigits($1)) ne ""
Truth table33%1/3
A and B
A= $number =~ /^([0-9]+)(?:.(B\d\d))?$/B= (my $cd = $self->_compute_checkdigits($1)) ne ""
| |||||||||||||||||||||||||||||
| 32 | and (my $cd = $self->_compute_checkdigits($1)) ne '') { | ||||||||||||||||||||||||||||
| 33 | 2 | ▶ | my $tail = $2 || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$2 || ''
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||
| 34 | 2 | return $1 . $cd . $tail; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | return ''; | |||||||||||||||||||||||||||
| 37 | } # complete() | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub basenumber { | ||||||||||||||||||||||||||
|
Subroutine
basenumber: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 2 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 41 | 2 | ▶ | if ($number =~ /^([0-9]+)(\d)(B\d\d)?$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | my $tail = $3 ? ".$3" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | return $1 . $tail if ($2 == $self->_compute_checkdigits($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 =~ /^([0-9]+)(\d)(B\d\d)?$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | return $2 if ($2 == $self->_compute_checkdigits($1)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | return ''; | |||||||||||||||||||||||||||
| 54 | } # checkdigit() | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 10 | ▶ | sub _compute_checkdigits { | ||||||||||||||||||||||||||
|
Subroutine
_compute_checkdigits: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 57 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 10 | my $number = shift; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 10 | $number =~ s/\.//g; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 10 | my @digits = split(//,$number); | |||||||||||||||||||||||||||
| 63 | 10 | my $len = scalar(@digits) + 1; | |||||||||||||||||||||||||||
| 64 | 10 | my $sum = 0; | |||||||||||||||||||||||||||
| 65 | 10 | ▶ | for (my $i = 0; $i <= $#digits; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 80 | $sum += ($len - $i) * $digits[$i]; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 10 | $sum %= 11; | |||||||||||||||||||||||||||
| 69 | 10 | ▶ | return ($sum == 10) ? '' : $sum; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } # _compute_checkdigit() | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Preloaded methods go here. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||