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