line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M11_016; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
35
|
use 5.006; |
|
2
|
|
|
|
|
7
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
37
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
6
|
2
|
|
|
2
|
|
401
|
use integer; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
20
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
53
|
use version; our $VERSION = 'v1.3.4'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
10
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Algorithm::CheckDigits); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @weight = ( 6, 5, 7, 2, 3, 4, 5, 6, 7 ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
2
|
|
|
2
|
0
|
5
|
my $proto = shift; |
16
|
2
|
|
|
|
|
3
|
my $type = shift; |
17
|
2
|
|
33
|
|
|
15
|
my $class = ref($proto) || $proto; |
18
|
2
|
|
|
|
|
5
|
my $self = bless({}, $class); |
19
|
2
|
|
|
|
|
15
|
$self->{type} = lc($type); |
20
|
2
|
|
|
|
|
9
|
return $self; |
21
|
|
|
|
|
|
|
} # new() |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub is_valid { |
24
|
12
|
|
|
12
|
1
|
31
|
my ($self,$number) = @_; |
25
|
12
|
50
|
|
|
|
52
|
if ($number =~ /^(\d{9})(\d)$/) { |
26
|
12
|
|
|
|
|
25
|
return $2 == $self->_compute_checkdigits($1); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
0
|
return '' |
29
|
|
|
|
|
|
|
} # is_valid() |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub complete { |
32
|
2
|
|
|
2
|
1
|
99
|
my ($self,$number) = @_; |
33
|
2
|
50
|
|
|
|
11
|
if ($number =~ /^(\d{9})$/) { |
34
|
2
|
|
|
|
|
10
|
return "$1" . $self->_compute_checkdigits($1); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
0
|
return ''; |
37
|
|
|
|
|
|
|
} # complete() |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub basenumber { |
40
|
1
|
|
|
1
|
1
|
4
|
my ($self,$number) = @_; |
41
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^(\d{9})(\d)$/) { |
42
|
1
|
50
|
|
|
|
3
|
return $1 if ($2 == $self->_compute_checkdigits($1)); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
return ''; |
45
|
|
|
|
|
|
|
} # basenumber() |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub checkdigit { |
48
|
1
|
|
|
1
|
1
|
4
|
my ($self,$number) = @_; |
49
|
1
|
50
|
|
|
|
7
|
if ($number =~ /^(\d{9})(\d)$/) { |
50
|
1
|
50
|
|
|
|
3
|
return $2 if ($2 == $self->_compute_checkdigits($1)); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
0
|
return ''; |
53
|
|
|
|
|
|
|
} # checkdigit() |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _compute_checkdigits { |
56
|
16
|
|
|
16
|
|
22
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
16
|
|
|
|
|
61
|
my @digits = split(//,shift); |
59
|
16
|
|
|
|
|
21
|
my $sum = 0; |
60
|
16
|
|
|
|
|
40
|
for (my $i = 0; $i <= $#digits; $i++) { |
61
|
144
|
|
|
|
|
248
|
$sum += $weight[$i] * $digits[$i]; |
62
|
|
|
|
|
|
|
} |
63
|
16
|
|
|
|
|
23
|
$sum %= 11; |
64
|
16
|
|
|
|
|
88
|
return $sum; |
65
|
|
|
|
|
|
|
} # _compute_checkdigit() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Preloaded methods go here. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
__END__ |