| 1 | package Algorithm::CheckDigits::M07_001; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use version; our $VERSION = 'v1.3.6'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 12 | 0 | my $proto = shift; | |||||||||||||||||||
| 13 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 14 | 0 | return bless({}, $class); | |||||||||||||||||||
| 15 | } # new() | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 18 | 0 | my ($self,$number) = @_; | |||||||||||||||||||
| 19 | 0 | ▶ | if ($number =~ /^([0-9]*)([0-9])$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | return ($2 == _compute_checkdigit($1)); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | 0 | return 0; | |||||||||||||||||||
| 23 | } # is_valid() | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 26 | 0 | my ($self,$number) = @_; | |||||||||||||||||||
| 27 | 0 | ▶ | if ($number =~ /^([0-9]*)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 0 | return $number . _compute_checkdigit($1); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | 0 | return undef; | |||||||||||||||||||
| 31 | } # complete() | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 34 | 0 | my ($self,$number) = @_; | |||||||||||||||||||
| 35 | 0 | ▶ | if ($number =~ /^([0-9]*)([0-9])$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | ▶ | return $1 if ($2 == _compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 0 | return undef; | |||||||||||||||||||
| 39 | } # basenumber() | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 42 | 0 | my ($self,$number) = @_; | |||||||||||||||||||
| 43 | 0 | ▶ | if ($number =~ /^([0-9]*)([0-9])$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | ▶ | return $2 if ($2 == _compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | return undef; | |||||||||||||||||||
| 47 | } # checkdigit() | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 50 | 0 | my $number = shift; | |||||||||||||||||||
| 51 | 0 | my @digits = split(//,$number); | |||||||||||||||||||
| 52 | 0 | my $even = 0; | |||||||||||||||||||
| 53 | 0 | my $sum = 0; | |||||||||||||||||||
| 54 | 0 | foreach my $digit (@digits) { | |||||||||||||||||||
| 55 | 0 | $sum += $digit; | |||||||||||||||||||
| 56 | 0 | ▶ | $sum += $digit if ($even); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | $even = not $even; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 0 | return $sum % 7; | |||||||||||||||||||
| 60 | } # _compute_checkdigit() | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # Preloaded methods go here. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | 1; | |||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||