line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M11_009; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
7
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21
|
use version; our $VERSION = 'v1.3.5'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Algorithm::CheckDigits); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @weight = ( 2, 7, 6, 5, 4, 3, 2 ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my @keys = ('', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'Z', 'J' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
2
|
|
|
2
|
0
|
5
|
my $proto = shift; |
18
|
2
|
|
|
|
|
4
|
my $type = shift; |
19
|
2
|
|
33
|
|
|
9
|
my $class = ref($proto) || $proto; |
20
|
2
|
|
|
|
|
4
|
my $self = bless({}, $class); |
21
|
2
|
|
|
|
|
12
|
$self->{type} = lc($type); |
22
|
2
|
|
|
|
|
11
|
return $self; |
23
|
|
|
|
|
|
|
} # new() |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub is_valid { |
26
|
4
|
|
|
4
|
1
|
16
|
my ($self,$number) = @_; |
27
|
4
|
50
|
|
|
|
24
|
if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) { |
28
|
4
|
|
|
|
|
13
|
return (uc($3) eq $self->_compute_checkdigits($2)); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
0
|
return '' |
31
|
|
|
|
|
|
|
} # is_valid() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub complete { |
34
|
2
|
|
|
2
|
1
|
156
|
my ($self,$number) = @_; |
35
|
2
|
50
|
|
|
|
12
|
if($number =~ /^([fgst])?(\d{7})$/i) { |
36
|
2
|
|
100
|
|
|
14
|
my $prefix = $1 || ''; |
37
|
2
|
|
|
|
|
9
|
return $prefix . $2 . $self->_compute_checkdigits($2); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
0
|
return ''; |
40
|
|
|
|
|
|
|
} # complete() |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub basenumber { |
43
|
2
|
|
|
2
|
1
|
5
|
my ($self,$number) = @_; |
44
|
2
|
50
|
33
|
|
|
17
|
if( $number =~ /^([fgst])?(\d{7})([a-jz])$/i |
45
|
|
|
|
|
|
|
and uc($3) eq $self->_compute_checkdigits($2)) { |
46
|
2
|
|
100
|
|
|
10
|
my $prefix = $1 || ''; |
47
|
2
|
|
|
|
|
12
|
return $prefix . $2; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
0
|
return ''; |
50
|
|
|
|
|
|
|
} # basenumber() |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub checkdigit { |
53
|
2
|
|
|
2
|
1
|
7
|
my ($self,$number) = @_; |
54
|
2
|
50
|
|
|
|
13
|
if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) { |
55
|
2
|
|
|
|
|
5
|
return $self->_compute_checkdigits($2); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
return undef; |
58
|
|
|
|
|
|
|
} # checkdigit() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _compute_checkdigits { |
61
|
10
|
|
|
10
|
|
14
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
10
|
|
|
|
|
37
|
my @digits = split(//,shift); |
64
|
10
|
|
|
|
|
15
|
my $sum = 0; |
65
|
10
|
|
|
|
|
25
|
for (my $i = 0; $i <= $#digits; $i++) { |
66
|
70
|
|
|
|
|
140
|
$sum += $weight[$i] * $digits[$i]; |
67
|
|
|
|
|
|
|
} |
68
|
10
|
|
|
|
|
17
|
$sum %= 11; |
69
|
10
|
|
|
|
|
52
|
return $keys[11 - $sum]; |
70
|
|
|
|
|
|
|
} # _compute_checkdigit() |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Preloaded methods go here. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
__END__ |