line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M43_001; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
22
|
use version; our $VERSION = 'v1.3.5'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Algorithm::CheckDigits); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %keytable = ( |
13
|
|
|
|
|
|
|
'0' => 0, '1' => 1, '2' => 2, '3' => 3, |
14
|
|
|
|
|
|
|
'4' => 4, '5' => 5, '6' => 6, '7' => 7, |
15
|
|
|
|
|
|
|
'8' => 8, '9' => 9, 'A' => 10, 'B' => 11, |
16
|
|
|
|
|
|
|
'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, |
17
|
|
|
|
|
|
|
'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, |
18
|
|
|
|
|
|
|
'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, |
19
|
|
|
|
|
|
|
'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, |
20
|
|
|
|
|
|
|
'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, |
21
|
|
|
|
|
|
|
'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35, |
22
|
|
|
|
|
|
|
'-' => 36, '.' => 37, ' ' => 38, '$' => 39, |
23
|
|
|
|
|
|
|
'/' => 40, '+' => 41, '%' => 42, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %keymap = reverse %keytable; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
1
|
|
|
1
|
0
|
2
|
my $proto = shift; |
30
|
1
|
|
|
|
|
3
|
my $type = shift; |
31
|
1
|
|
33
|
|
|
6
|
my $class = ref($proto) || $proto; |
32
|
1
|
|
|
|
|
3
|
my $self = bless({}, $class); |
33
|
1
|
|
|
|
|
9
|
$self->{type} = lc($type); |
34
|
1
|
|
|
|
|
5
|
return $self; |
35
|
|
|
|
|
|
|
} # new() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub is_valid { |
38
|
2
|
|
|
2
|
1
|
8
|
my ($self,$number) = @_; |
39
|
2
|
50
|
|
|
|
13
|
if ($number =~ /^(.*)(.)$/i) { |
40
|
2
|
|
|
|
|
5
|
return $2 eq $self->_compute_checkdigit($1); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
return '' |
43
|
|
|
|
|
|
|
} # is_valid() |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub complete { |
46
|
1
|
|
|
1
|
1
|
97
|
my ($self,$number) = @_; |
47
|
1
|
50
|
|
|
|
7
|
if ($number =~ /^(.*)$/i) { |
48
|
1
|
|
|
|
|
4
|
return $number . $self->_compute_checkdigit($1); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
return ''; |
51
|
|
|
|
|
|
|
} # complete() |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub basenumber { |
54
|
1
|
|
|
1
|
1
|
4
|
my ($self,$number) = @_; |
55
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^(.*)(.)$/i) { |
56
|
1
|
50
|
|
|
|
5
|
return $1 if (uc($2) eq $self->_compute_checkdigit($1)); |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
0
|
return ''; |
59
|
|
|
|
|
|
|
} # basenumber() |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub checkdigit { |
62
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
63
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^(.*)(.)$/i) { |
64
|
1
|
50
|
|
|
|
4
|
return $2 if (uc($2) eq $self->_compute_checkdigit($1)); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
0
|
return ''; |
67
|
|
|
|
|
|
|
} # checkdigit() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _compute_checkdigit { |
70
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
71
|
5
|
|
|
|
|
10
|
my $number = shift; |
72
|
5
|
|
|
|
|
9
|
my $sum = 0; |
73
|
|
|
|
|
|
|
|
74
|
5
|
|
|
|
|
18
|
my @digits = split(//,$number); |
75
|
|
|
|
|
|
|
|
76
|
5
|
|
|
|
|
14
|
for (my $i = 0; $i < length($number); $i++) { |
77
|
30
|
|
|
|
|
62
|
$sum += $keytable{$digits[$i]}; |
78
|
|
|
|
|
|
|
} |
79
|
5
|
|
|
|
|
7
|
$sum %= 43; |
80
|
5
|
|
|
|
|
36
|
return $keymap{$sum}; |
81
|
|
|
|
|
|
|
} # _compute_checkdigit() |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Preloaded methods go here. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |