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