| 1 | package Algorithm::CheckDigits::M11_012; | ||||||||||||||||||||||||||||
| 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 = ( 2,3,4,5,6,7,1,6,7,2,3 ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | my %table_to = ( | |||||||||||||||||||||||||||
| 15 | 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, | ||||||||||||||||||||||||||||
| 16 | 6 => 6, 7 => 7, 8 => 8, 9 => 9, A => 12, B => 14, | ||||||||||||||||||||||||||||
| 17 | C => 16, D => 18, E => 20, F => 22, G => 24, H => 26, | ||||||||||||||||||||||||||||
| 18 | I => 28, J => 6, K => 8, L => 10, M => 12, N => 14, | ||||||||||||||||||||||||||||
| 19 | O => 16, P => 18, Q => 20, R => 22, S => 4, T => 6, | ||||||||||||||||||||||||||||
| 20 | U => 8, V => 10, W => 12, X => 14, Y => 16, Z => 18, | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 1 | my $proto = shift; | |||||||||||||||||||||||||||
| 25 | 1 | my $type = shift; | |||||||||||||||||||||||||||
| 26 | 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
| |||||||||||||||||||||||||||||
| 27 | 1 | my $self = bless({}, $class); | |||||||||||||||||||||||||||
| 28 | 1 | $self->{type} = lc($type); | |||||||||||||||||||||||||||
| 29 | 1 | return $self; | |||||||||||||||||||||||||||
| 30 | } # new() | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | sub is_valid { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 2 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 34 | 2 | ▶ | if ($number =~ /^([-0-9a-z]+)(\d)$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | return $2 == $self->_compute_checkdigits($1); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | return undef; | |||||||||||||||||||||||||||
| 38 | } # is_valid() | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub complete { | ||||||||||||||||||||||||||
|
Subroutine
complete: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 1 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 42 | 1 | ▶ | if ($number =~ /^([-0-9a-z]+)$/i | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$number =~ /^([-0-9a-z]+)$/i and (my $cd = $self->_compute_checkdigits($1)) ne ""
MC/DC0%0/2
$number =~ /^([-0-9a-z]+)$/i and (my $cd = $self->_compute_checkdigits($1)) ne ""
$number =~ /^([-0-9a-z]+)$/i
(my $cd = $self->_compute_checkdigits($1)) ne ""
Truth table33%1/3
A and B
A= $number =~ /^([-0-9a-z]+)$/iB= (my $cd = $self->_compute_checkdigits($1)) ne ""
| |||||||||||||||||||||||||||||
| 43 | and (my $cd = $self->_compute_checkdigits($1)) ne '') { | ||||||||||||||||||||||||||||
| 44 | 1 | return $1 . $cd; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | return undef; | |||||||||||||||||||||||||||
| 47 | } # complete() | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub basenumber { | ||||||||||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 1 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 51 | 1 | ▶ | if ($number =~ /^([-0-9a-z]+)(\d)$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | return $1 if ($2 == $self->_compute_checkdigits($1)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | return undef; | |||||||||||||||||||||||||||
| 55 | } # basenumber() | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 1 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 59 | 1 | ▶ | if ($number =~ /^([-0-9a-z]+)(\d)$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | return $2 if ($2 == $self->_compute_checkdigits($1)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | return undef; | |||||||||||||||||||||||||||
| 63 | } # checkdigit() | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 5 | ▶ | sub _compute_checkdigits { | ||||||||||||||||||||||||||
|
Subroutine
_compute_checkdigits: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 66 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 5 | my $number = shift; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | $number =~ s/-//g; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 5 | my @digits = split(//,$number); | |||||||||||||||||||||||||||
| 72 | 5 | my $len = scalar(@digits) + 1; | |||||||||||||||||||||||||||
| 73 | 5 | my $sum = 0; | |||||||||||||||||||||||||||
| 74 | 5 | ▶ | for (my $i = 0; $i <= $#digits; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 55 | $sum += $weight[$i] * $table_to{uc($digits[$i])}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 5 | $sum %= 11; | |||||||||||||||||||||||||||
| 78 | 5 | ▶ | return ($sum == 0) ? 1 : ($sum == 1) ? 0 : 11 - $sum; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 79 | } # _compute_checkdigit() | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Preloaded methods go here. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||