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