| 1 | package Algorithm::CheckDigits::M10_008; | ||||||||||||||||||||
| 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 = qv('v1.3.6'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | our @ISA = qw(Algorithm::CheckDigits); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 3 | my @weight = ( 1,3,1,7,3,9,1 ); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 3 | my $value = 0; | |||||||||||||||||||
| 15 | 3 | my %ctable = map { $_, $value++ } ( '0'..'9', 'A'..'Z' ); | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 3 | my $re_alpha = qr/[B-DF-HJ-NP-TV-Z]/; | |||||||||||||||||||
| 18 | 3 | my $re_alnum = qr/[0-9B-DF-HJ-NP-TV-Z]/; | |||||||||||||||||||
| 19 | 3 | my $re_sedol = qr/(\d{6}|$re_alpha$re_alnum{5})(\d)?/; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 22 | 3 | my $proto = shift; | |||||||||||||||||||
| 23 | 3 | my $type = shift; | |||||||||||||||||||
| 24 | 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
| |||||||||||||||||||||
| 25 | 3 | my $self = bless({}, $class); | |||||||||||||||||||
| 26 | 3 | $self->{type} = lc($type); | |||||||||||||||||||
| 27 | 3 | return $self; | |||||||||||||||||||
| 28 | } # new() | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 30 | ▶ | sub is_valid { | ||||||||||||||||||
|
Subroutine
is_valid: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 31 | 30 | my $self = shift; | |||||||||||||||||||
| 32 | 30 | my $number = uc shift; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 30 | ▶ | if ($number =~ /^$re_sedol$/o) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 30 | return $2 == $self->_compute_checkdigit($1); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | 0 | return '' | |||||||||||||||||||
| 38 | } # is_valid() | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 15 | ▶ | sub complete { | ||||||||||||||||||
|
Subroutine
complete: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 41 | 15 | my $self = shift; | |||||||||||||||||||
| 42 | 15 | my $number = uc shift; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 15 | ▶ | if ($number =~ /^$re_sedol$/o) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 15 | return $number . $self->_compute_checkdigit($number); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||
| 48 | 0 | return ''; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | } # complete() | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 15 | ▶ | sub basenumber { | ||||||||||||||||||
|
Subroutine
basenumber: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||
| 53 | 15 | my $self = shift; | |||||||||||||||||||
| 54 | 15 | my $number = uc shift; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 15 | ▶ | if ($number =~ /^$re_sedol$/o) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 15 | ▶ | return $1 if ($2 == $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 0 | return ''; | |||||||||||||||||||
| 60 | } # basenumber() | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 15 | ▶ | sub checkdigit { | ||||||||||||||||||
|
Subroutine
checkdigit: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||
| 63 | 15 | my $self = shift; | |||||||||||||||||||
| 64 | 15 | my $number = uc shift; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 15 | ▶ | if ($number =~ /^$re_sedol$/o) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 15 | ▶ | return $2 if ($2 == $self->_compute_checkdigit($1)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 0 | return ''; | |||||||||||||||||||
| 70 | } # checkdigit() | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 75 | ▶ | sub _compute_checkdigit { | ||||||||||||||||||
|
Subroutine
_compute_checkdigit: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 73 | 75 | my $self = shift; | |||||||||||||||||||
| 74 | 75 | my $number = shift; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 75 | my @digits = map { $ctable{$_} } split(//,$number); | |||||||||||||||||||
| 78 | 75 | my $sum = 0; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 75 | ▶ | for (my $i = 0; $i <= $#digits; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 450 | $sum += $weight[$i] * $digits[$i]; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 75 | return (10 - ($sum % 10)) % 10; | |||||||||||||||||||
| 86 | } # _compute_checkdigit() | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | # Preloaded methods go here. | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 3 | 1; | |||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||