line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M89_001; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
6
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21
|
use version; our $VERSION = 'v1.3.6'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Algorithm::CheckDigits); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @keytable = ( |
13
|
|
|
|
|
|
|
'T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', |
14
|
|
|
|
|
|
|
'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', |
15
|
|
|
|
|
|
|
'Q', 'V', 'H', 'L', 'C', 'K', 'E', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
0
|
3
|
my $proto = shift; |
20
|
1
|
|
|
|
|
2
|
my $type = shift; |
21
|
1
|
|
33
|
|
|
6
|
my $class = ref($proto) || $proto; |
22
|
1
|
|
|
|
|
2
|
my $self = bless({}, $class); |
23
|
1
|
|
|
|
|
8
|
$self->{type} = lc($type); |
24
|
1
|
|
|
|
|
6
|
return $self; |
25
|
|
|
|
|
|
|
} # new() |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub is_valid { |
28
|
2
|
|
|
2
|
1
|
8
|
my ($self,$number) = @_; |
29
|
2
|
50
|
|
|
|
13
|
if ($number =~ /^(\d{6})?(\d\d)$/i) { |
30
|
2
|
|
|
|
|
6
|
return $2 eq $self->_compute_checkdigit($1); |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
0
|
return '' |
33
|
|
|
|
|
|
|
} # is_valid() |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub complete { |
36
|
1
|
|
|
1
|
1
|
95
|
my ($self,$number) = @_; |
37
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^(\d{6})$/i) { |
38
|
1
|
|
|
|
|
3
|
return $number . $self->_compute_checkdigit($1); |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
0
|
return ''; |
41
|
|
|
|
|
|
|
} # complete() |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub basenumber { |
44
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
45
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^(\d{6})(\d\d)$/i) { |
46
|
1
|
50
|
|
|
|
3
|
return $1 if ($2 eq $self->_compute_checkdigit($1)); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
0
|
return ''; |
49
|
|
|
|
|
|
|
} # basenumber() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub checkdigit { |
52
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
53
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^(\d{6})(\d\d)$/i) { |
54
|
1
|
50
|
|
|
|
5
|
return $2 if (uc($2) eq $self->_compute_checkdigit($1)); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
0
|
return ''; |
57
|
|
|
|
|
|
|
} # checkdigit() |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _compute_checkdigit { |
60
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
61
|
5
|
|
|
|
|
13
|
my $number = shift; |
62
|
|
|
|
|
|
|
|
63
|
5
|
50
|
|
|
|
29
|
if ($number =~ /^\d{6}$/i) { |
64
|
5
|
|
|
|
|
46
|
return sprintf("%2.2d",($number % 89)); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return -1; |
67
|
|
|
|
|
|
|
} # _compute_checkdigit() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Preloaded methods go here. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |