line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M09_001; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use version; our $VERSION = 'v1.3.6'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Algorithm::CheckDigits); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
0
|
5
|
my $proto = shift; |
13
|
2
|
|
33
|
|
|
10
|
my $class = ref($proto) || $proto; |
14
|
2
|
|
|
|
|
11
|
return bless({}, $class); |
15
|
|
|
|
|
|
|
} # new() |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub is_valid { |
18
|
4
|
|
|
4
|
1
|
18
|
my ($self,$number) = @_; |
19
|
4
|
50
|
|
|
|
20
|
if ($number =~ /^([A-Za-z][0-9]{10})([0-9])$/) { |
20
|
4
|
|
|
|
|
9
|
return $2 == _compute_checkdigit($1); |
21
|
|
|
|
|
|
|
} |
22
|
0
|
|
|
|
|
0
|
return 0; |
23
|
|
|
|
|
|
|
} # is_valid() |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub complete { |
26
|
2
|
|
|
2
|
1
|
149
|
my ($self,$number) = @_; |
27
|
2
|
50
|
|
|
|
10
|
if ($number =~ /^[A-Za-z][0-9]{10}$/) { |
28
|
2
|
|
|
|
|
4
|
return $number . _compute_checkdigit($number); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
0
|
return ''; |
31
|
|
|
|
|
|
|
} # complete() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub basenumber { |
34
|
2
|
|
|
2
|
1
|
5
|
my ($self,$number) = @_; |
35
|
2
|
50
|
|
|
|
9
|
if ($number =~ /^([A-Za-z][0-9]{10})([0-9])$/) { |
36
|
2
|
50
|
|
|
|
5
|
return $1 if ($2 == _compute_checkdigit($1)); |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
0
|
return ''; |
39
|
|
|
|
|
|
|
} # basenumber() |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub checkdigit { |
42
|
2
|
|
|
2
|
1
|
5
|
my ($self,$number) = @_; |
43
|
2
|
50
|
|
|
|
10
|
if ($number =~ /^([A-Za-z][0-9]{10})([0-9])$/) { |
44
|
2
|
50
|
|
|
|
5
|
return $2 if ($2 == _compute_checkdigit($1)); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
0
|
return ''; |
47
|
|
|
|
|
|
|
} # checkdigit() |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _compute_checkdigit { |
50
|
10
|
|
|
10
|
|
23
|
my $number = shift; |
51
|
10
|
50
|
|
|
|
28
|
if ($number =~ /^([A-Za-z])([0-9]{10})$/) { |
52
|
10
|
|
|
|
|
17
|
my @nums = (); |
53
|
10
|
|
|
|
|
15
|
my $sum = 0; |
54
|
10
|
|
|
|
|
56
|
push(@nums,ord(uc($1)) - ord('A') +1); |
55
|
10
|
|
|
|
|
48
|
push(@nums,split(//,$2)); |
56
|
10
|
|
|
|
|
23
|
foreach my $num (@nums) { |
57
|
110
|
|
|
|
|
161
|
$sum += $num; |
58
|
|
|
|
|
|
|
} |
59
|
10
|
|
|
|
|
69
|
return 8 - ($sum % 9); |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return -1; |
62
|
|
|
|
|
|
|
} # _compute_checkdigit() |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Preloaded methods go here. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |