| 1 | package Algorithm::CheckDigits::M97_001; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | ▶ | use integer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | ▶ | use version; our $VERSION = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 13 | 3 | my $proto = shift; | |||||||||||||||||||
| 14 | 3 | my $type = shift; | |||||||||||||||||||
| 15 | 3 | ▶ | 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 | 3 | my $self = bless({}, $class); | |||||||||||||||||||
| 17 | 3 | $self->{type} = lc($type); | |||||||||||||||||||
| 18 | 3 | return $self; | |||||||||||||||||||
| 19 | } # new() | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 5 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 22 | 5 | my ($self,$number) = @_; | |||||||||||||||||||
| 23 | 5 | ▶ | if ($number =~ /^(?:BE)?(\d{7,8})?(\d\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 5 | return $2 eq $self->_compute_checkdigit($1); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | 0 | return '' | |||||||||||||||||||
| 27 | } # is_valid() | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 3 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 30 | 3 | my ($self,$number) = @_; | |||||||||||||||||||
| 31 | 3 | ▶ | if ($number =~ /^(?:BE)?(\d{7,8})$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 3 | return $number . $self->_compute_checkdigit($1); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | 0 | return ''; | |||||||||||||||||||
| 35 | } # complete() | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 3 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 38 | 3 | my ($self,$number) = @_; | |||||||||||||||||||
| 39 | 3 | ▶ | if ($number =~ /^(?:BE)?(\d{7,8})(\d\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 3 | ▶ | return $1 if ($2 eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | 0 | return ''; | |||||||||||||||||||
| 43 | } # basenumber() | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 3 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 46 | 3 | my ($self,$number) = @_; | |||||||||||||||||||
| 47 | 3 | ▶ | if ($number =~ /^(?:BE)?(\d{7,8})(\d\d)$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 3 | ▶ | return $2 if (uc($2) eq $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | 0 | return ''; | |||||||||||||||||||
| 51 | } # checkdigit() | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 14 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 54 | 14 | my $self = shift; | |||||||||||||||||||
| 55 | 14 | my $number = shift; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 14 | ▶ | if ($number =~ /^\d{7,8}$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 14 | return sprintf("%2.2d",97 - ($number % 97)); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | 0 | return -1; | |||||||||||||||||||
| 61 | } # _compute_checkdigit() | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # Preloaded methods go here. | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 3 | 1; | |||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||