| 1 | # vim: set ts=4 sw=4 tw=78 et si: | ||||||||||||||||||||
| 2 | package Algorithm::CheckDigits::MXX_002; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use integer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use version; our $VERSION = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 14 | 3 | my $proto = shift; | |||||||||||||||||||
| 15 | 3 | my $type = shift; | |||||||||||||||||||
| 16 | 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
| |||||||||||||||||||||
| 17 | 3 | my $self = bless( {}, $class ); | |||||||||||||||||||
| 18 | 3 | $self->{type} = lc($type); | |||||||||||||||||||
| 19 | 3 | return $self; | |||||||||||||||||||
| 20 | } # new() | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 6 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 23 | 6 | my ( $self, $number ) = @_; | |||||||||||||||||||
| 24 | 6 | ▶ | if ( $number =~ /^(\d{1,7}-?\d{2}-?)(\d)$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 6 | ▶ | return 1 if ( $2 == $self->_compute_checkdigit($1) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | 3 | return ''; | |||||||||||||||||||
| 28 | } # is_valid() | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 3 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 31 | 3 | my ( $self, $number ) = @_; | |||||||||||||||||||
| 32 | 3 | ▶ | if ( $number =~ /^\d{1,7}-?\d{2}-?$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 3 | return $number . $self->_compute_checkdigit($number); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | 0 | return ''; | |||||||||||||||||||
| 36 | } # complete() | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 3 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 39 | 3 | my ( $self, $number ) = @_; | |||||||||||||||||||
| 40 | 3 | ▶ | if ( $number =~ /^(\d{1,7}-?\d{2}-?)(\d)$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 3 | ▶ | return $1 if ( $2 == $self->_compute_checkdigit($1) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | 0 | return ''; | |||||||||||||||||||
| 44 | } # basenumber() | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 3 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 47 | 3 | my ( $self, $number ) = @_; | |||||||||||||||||||
| 48 | 3 | ▶ | if ( $number =~ /^(\d{1,7}-?\d{2}-?)(\d)$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 3 | ▶ | return $2 if ( $2 == $self->_compute_checkdigit($1) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | 0 | return ''; | |||||||||||||||||||
| 52 | } # checkdigit() | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 15 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 55 | 15 | my $self = shift; | |||||||||||||||||||
| 56 | 15 | my $number = shift; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 15 | $number =~ s/-//g; | |||||||||||||||||||
| 59 | 15 | my @digits = split( //, $number ); | |||||||||||||||||||
| 60 | 15 | my $weight = 1; | |||||||||||||||||||
| 61 | 15 | my $sum = 0; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 15 | ▶ | for ( my $i = $#digits; $i >= 0; $i-- ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 100 | $sum += $digits[$i] * $weight++; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 15 | return $sum % 10; | |||||||||||||||||||
| 68 | } # _compute_checkdigit() | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | # Preloaded methods go here. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||