| 1 | package Algorithm::CheckDigits::M16_001; | ||||||||||||||||||||
| 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 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 13 | 1 | my $proto = shift; | |||||||||||||||||||
| 14 | 1 | my $type = shift; | |||||||||||||||||||
| 15 | 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
| |||||||||||||||||||||
| 16 | 1 | my $self = bless({}, $class); | |||||||||||||||||||
| 17 | 1 | $self->{type} = lc($type); | |||||||||||||||||||
| 18 | 1 | return $self; | |||||||||||||||||||
| 19 | } # new() | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 22 | 2 | my ($self,$number) = @_; | |||||||||||||||||||
| 23 | 2 | ▶ | if ($number =~ /^([0-9a-f]{15})([0-9a-f])$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 2 | return $2 eq $self->_compute_checkdigit($1); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | 0 | return '' | |||||||||||||||||||
| 27 | } # is_valid() | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 30 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 31 | 1 | ▶ | if ($number =~ /^[0-9a-f]{15}$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 1 | return $number . $self->_compute_checkdigit($number); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | 0 | return ''; | |||||||||||||||||||
| 35 | } # complete() | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 38 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 39 | 1 | ▶ | if ($number =~ /^([0-9a-f]{15})([0-9a-f])$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 1 | ▶ | return $1 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | 0 | return ''; | |||||||||||||||||||
| 43 | } # basenumber() | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 1 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 46 | 1 | my ($self,$number) = @_; | |||||||||||||||||||
| 47 | 1 | ▶ | if ($number =~ /^([0-9a-f]{15})([0-9a-f])$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 1 | ▶ | return $2 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | 0 | return ''; | |||||||||||||||||||
| 51 | } # checkdigit() | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 5 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=4 SCAR=14.0
| |||||||||||||||||||||
| 54 | 5 | my $self = shift; | |||||||||||||||||||
| 55 | 5 | my $number = shift; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 5 | ▶ | if ($number =~ /^[0-9a-f]{15}$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 5 | my ($a,$b,$c); | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 5 | my @digits = split(//,$number); | |||||||||||||||||||
| 61 | 5 | $a = 16; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 5 | ▶ | for (my $i = 0; $i <= $#digits; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 75 | $b = ($a % 17) + hex($digits[$i]); | |||||||||||||||||||
| 66 | 75 | $c = $b % 16; | |||||||||||||||||||
| 67 | 75 | ▶ | $c = 16 unless ($c); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 75 | $a = 2 * $c; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 5 | return sprintf("%X",(17 - ($a % 17)) % 16); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 0 | return -1; | |||||||||||||||||||
| 74 | } # _compute_checkdigit() | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | # Preloaded methods go here. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 2 | 1; | |||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||