| 1 | package Algorithm::CheckDigits::M11_001; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use integer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | ▶ | use version; our $VERSION = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 5 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | my $cd = { | |||||||||||||||||||
| 13 | 'isbn' => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'X', 0 ], | ||||||||||||||||||||
| 14 | 'ustid_pt' => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0 ], | ||||||||||||||||||||
| 15 | 'hkid' => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 0 ], | ||||||||||||||||||||
| 16 | 'wagonnr_br' => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 ], | ||||||||||||||||||||
| 17 | 'nhs_gb' => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, 0 ], | ||||||||||||||||||||
| 18 | 'vat_sl' => [ 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1 ], # ? | ||||||||||||||||||||
| 19 | }; | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 5 | $cd->{'issn'} = $cd->{'isbn'}; | |||||||||||||||||||
| 22 | 5 | $cd->{'vatrn_pt'} = $cd->{'ustid_pt'}; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 11 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 25 | 11 | my $proto = shift; | |||||||||||||||||||
| 26 | 11 | my $type = shift; | |||||||||||||||||||
| 27 | 11 | ▶ | 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
| |||||||||||||||||||||
| 28 | 11 | my $self = bless({}, $class); | |||||||||||||||||||
| 29 | 11 | $self->{type} = lc($type); | |||||||||||||||||||
| 30 | 11 | return $self; | |||||||||||||||||||
| 31 | } # new() | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 17 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 34 | 17 | my ($self,$number) = @_; | |||||||||||||||||||
| 35 | 17 | ▶ | if ($number =~ /^(.+)(.)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 17 | return uc($2) eq $self->_compute_checkdigit($1); | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 0 | return '' | |||||||||||||||||||
| 39 | } # is_valid() | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 9 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 42 | 9 | my ($self,$number) = @_; | |||||||||||||||||||
| 43 | 9 | ▶ | if ($number =~ /^[-0-9A-Za-z]+$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 9 | return $number . $self->_compute_checkdigit($number); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | return ''; | |||||||||||||||||||
| 47 | } # complete() | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 8 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 50 | 8 | my ($self,$number) = @_; | |||||||||||||||||||
| 51 | 8 | ▶ | if ($number =~ /^(.+)(.)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 8 | ▶ | return $1 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 0 | return ''; | |||||||||||||||||||
| 55 | } # basenumber() | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 9 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 58 | 9 | my ($self,$number) = @_; | |||||||||||||||||||
| 59 | 9 | ▶ | if ($number =~ /^(.+)(.)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 9 | ▶ | return $2 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | return ''; | |||||||||||||||||||
| 63 | } # checkdigit() | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 43 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=5 SCAR=16.2
| |||||||||||||||||||||
| 66 | 43 | my $self = shift; | |||||||||||||||||||
| 67 | 43 | my $number = shift; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 43 | ▶ | if ($number =~ /^[-0-9A-Za-z]+$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 43 | $number =~ s/-//g; | |||||||||||||||||||
| 72 | 43 | my @digits = split(//,$number); | |||||||||||||||||||
| 73 | 43 | my $sum = 0; | |||||||||||||||||||
| 74 | 43 | my $weight = 2; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 43 | ▶ | for (my $i = $#digits; $i >= 0; $i--) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 332 | ▶ | $digits[$i] = 1 + ord(uc($digits[$i])) - ord('A') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | if ($digits[$i] =~ /[A-Z]/i); | ||||||||||||||||||||
| 80 | 332 | $sum += $weight * $digits[$i]; | |||||||||||||||||||
| 81 | 332 | ++$weight; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | 43 | $sum %= 11; | |||||||||||||||||||
| 85 | 43 | ▶ | return $cd->{$self->{type}}[11-$sum] if ($cd->{$self->{type}}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | 0 | return -1; | |||||||||||||||||||
| 88 | } # _compute_checkdigit() | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | # Preloaded methods go here. | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 5 | 1; | |||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||