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