| 1 | package Algorithm::CheckDigits::MBase_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 = qv('v1.3.6'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | my @weight = ( 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 ); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | my %table_to = ( | |||||||||||||||||||
| 15 | '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, | ||||||||||||||||||||
| 16 | '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, | ||||||||||||||||||||
| 17 | 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, | ||||||||||||||||||||
| 18 | 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, | ||||||||||||||||||||
| 19 | 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, | ||||||||||||||||||||
| 20 | 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, | ||||||||||||||||||||
| 21 | 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, | ||||||||||||||||||||
| 22 | 'Z' => 35, | ||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 2 | my @table_from = ( | |||||||||||||||||||
| 26 | '0', '1', '2', '3', '4', | ||||||||||||||||||||
| 27 | '5', '6', '7', '8', '9', | ||||||||||||||||||||
| 28 | 'A', 'B', 'C', 'D', 'E', | ||||||||||||||||||||
| 29 | 'F', 'G', 'H', 'I', 'J', | ||||||||||||||||||||
| 30 | 'K', 'L', 'M', 'N', 'O', | ||||||||||||||||||||
| 31 | 'P', 'Q', 'R', 'S', 'T', | ||||||||||||||||||||
| 32 | 'U', 'V', 'W', 'X', 'Y', | ||||||||||||||||||||
| 33 | 'Z', '#', | ||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 37 | 1 | my $proto = shift; | |||||||||||||||||||
| 38 | 1 | my $type = shift; | |||||||||||||||||||
| 39 | 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
| |||||||||||||||||||||
| 40 | 1 | my $self = bless({}, $class); | |||||||||||||||||||
| 41 | 1 | $self->{type} = lc($type); | |||||||||||||||||||
| 42 | 1 | return $self; | |||||||||||||||||||
| 43 | } # new() | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 2 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 46 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 47 | 2 | ▶ | if ($number =~ /^(.*)(.)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 2 | return uc($2) eq $self->_compute_checkdigits($1); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | 0 | return '' | |||||||||||||||||||
| 51 | } # is_valid() | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 1 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 54 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 55 | 1 | ▶ | if ($number =~ /^(.*)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 1 | return "$1" | |||||||||||||||||||
| 57 | . $self->_compute_checkdigits($1) | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 0 | return ''; | |||||||||||||||||||
| 60 | } # complete() | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 63 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 64 | 1 | ▶ | if ($number =~ /^(.*)(.)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 1 | ▶ | return "$1" if ($2 eq $self->_compute_checkdigits($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 0 | return ''; | |||||||||||||||||||
| 68 | } # basenumber() | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 71 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 72 | 1 | ▶ | if ($number =~ /^(.*)(.)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 1 | ▶ | return $2 if ($2 eq $self->_compute_checkdigits($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 0 | return ''; | |||||||||||||||||||
| 76 | } # checkdigit() | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 5 | ▶ | sub _compute_checkdigits { | ||||||||||||||||||
|
Subroutine
_compute_checkdigits: called CC=5 SCAR=16.1
| |||||||||||||||||||||
| 79 | 5 | my $self = shift; | |||||||||||||||||||
| 80 | 5 | my $number = shift; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 5 | my $digit; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 5 | my @digits = split(//,$number); | |||||||||||||||||||
| 85 | 5 | my $even = 0; | |||||||||||||||||||
| 86 | 5 | my $sum1 = 0; | |||||||||||||||||||
| 87 | 5 | my $sum2 = 0; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 5 | ▶ | for (my $i = $#digits; $i>= 0; $i--) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 175 | ▶ | if (uc($digits[$i]) =~ /[0-9A-Z]/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 125 | $digit = $table_to{uc($digits[$i])}; | |||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||
| 93 | 50 | $digit = 36; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | 175 | ▶ | $sum1 += 3 * $digit unless ($even); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 175 | ▶ | $sum2 += $digit if ($even); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 175 | $even = not $even; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | 5 | my $sum = 37 - (($sum1 + $sum2) % 37); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 5 | return $table_from[$sum]; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | } # _compute_checkdigit() | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | # Preloaded methods go here. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 2 | 1; | |||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||