| 1 | package Algorithm::CheckDigits::M11_009; | ||||||||||||||||||||||||||||
| 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, 7, 6, 5, 4, 3, 2 ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | my @keys = ('', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'Z', 'J' ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 2 | my $proto = shift; | |||||||||||||||||||||||||||
| 18 | 2 | my $type = shift; | |||||||||||||||||||||||||||
| 19 | 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
| |||||||||||||||||||||||||||||
| 20 | 2 | my $self = bless({}, $class); | |||||||||||||||||||||||||||
| 21 | 2 | $self->{type} = lc($type); | |||||||||||||||||||||||||||
| 22 | 2 | return $self; | |||||||||||||||||||||||||||
| 23 | } # new() | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | sub is_valid { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 4 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 27 | 4 | ▶ | if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 4 | return (uc($3) eq $self->_compute_checkdigits($2)); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 0 | return '' | |||||||||||||||||||||||||||
| 31 | } # is_valid() | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | sub complete { | ||||||||||||||||||||||||||
|
Subroutine
complete: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 2 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 35 | 2 | ▶ | if($number =~ /^([fgst])?(\d{7})$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | my $prefix = $1 || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||
| 37 | 2 | return $prefix . $2 . $self->_compute_checkdigits($2); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 0 | return ''; | |||||||||||||||||||||||||||
| 40 | } # complete() | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub basenumber { | ||||||||||||||||||||||||||
|
Subroutine
basenumber: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 2 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 44 | 2 | ▶ | if( $number =~ /^([fgst])?(\d{7})([a-jz])$/i | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$number =~ /^([fgst])?(\d{7})([a-jz])$/i and uc $3 eq $self->_compute_checkdigits($2)
MC/DC0%0/2
$number =~ /^([fgst])?(\d{7})([a-jz])$/i and uc $3 eq $self->_compute_checkdigits($2)
$number =~ /^([fgst])?(\d{7})([a-jz])$/i
uc $3 eq $self->_compute_checkdigits($2)
Truth table33%1/3
A and B
A= $number =~ /^([fgst])?(\d{7})([a-jz])$/iB= uc $3 eq $self->_compute_checkdigits($2)
| |||||||||||||||||||||||||||||
| 45 | and uc($3) eq $self->_compute_checkdigits($2)) { | ||||||||||||||||||||||||||||
| 46 | 2 | ▶ | my $prefix = $1 || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||
| 47 | 2 | return $prefix . $2; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | return ''; | |||||||||||||||||||||||||||
| 50 | } # basenumber() | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | sub checkdigit { | ||||||||||||||||||||||||||
|
Subroutine
checkdigit: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 2 | my ($self,$number) = @_; | |||||||||||||||||||||||||||
| 54 | 2 | ▶ | if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | return $self->_compute_checkdigits($2); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 0 | return undef; | |||||||||||||||||||||||||||
| 58 | } # checkdigit() | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 10 | ▶ | sub _compute_checkdigits { | ||||||||||||||||||||||||||
|
Subroutine
_compute_checkdigits: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 61 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 10 | my @digits = split(//,shift); | |||||||||||||||||||||||||||
| 64 | 10 | my $sum = 0; | |||||||||||||||||||||||||||
| 65 | 10 | ▶ | for (my $i = 0; $i <= $#digits; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 70 | $sum += $weight[$i] * $digits[$i]; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 10 | $sum %= 11; | |||||||||||||||||||||||||||
| 69 | 10 | return $keys[11 - $sum]; | |||||||||||||||||||||||||||
| 70 | } # _compute_checkdigit() | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Preloaded methods go here. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||