line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M11_010; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
6
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
22
|
use version; our $VERSION = 'v1.3.4'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Algorithm::CheckDigits); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @weight = ( 5, 4, 3, 2, 7, 6, 5, 4, 3, 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
|
|
|
|
|
8
|
$self->{type} = lc($type); |
20
|
1
|
|
|
|
|
6
|
return $self; |
21
|
|
|
|
|
|
|
} # new() |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub is_valid { |
24
|
2
|
|
|
2
|
1
|
9
|
my ($self,$number) = @_; |
25
|
2
|
50
|
|
|
|
14
|
if ($number =~ /^([0-9.]+)(\d)$/) { |
26
|
2
|
|
|
|
|
5
|
return $2 == $self->_compute_checkdigits($1); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
0
|
return '' |
29
|
|
|
|
|
|
|
} # is_valid() |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub complete { |
32
|
1
|
|
|
1
|
1
|
95
|
my ($self,$number) = @_; |
33
|
1
|
50
|
|
|
|
8
|
if ($number =~ /^([0-9.]+)$/) { |
34
|
1
|
|
|
|
|
4
|
return "$1" . $self->_compute_checkdigits($1); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
0
|
return ''; |
37
|
|
|
|
|
|
|
} # complete() |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub basenumber { |
40
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
41
|
1
|
50
|
|
|
|
7
|
if ($number =~ /^([0-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
|
3
|
my ($self,$number) = @_; |
49
|
1
|
50
|
|
|
|
7
|
if ($number =~ /^([0-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
|
5
|
|
|
5
|
|
9
|
my $self = shift; |
57
|
5
|
|
|
|
|
12
|
my $number = shift; |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
|
|
22
|
$number =~ s/\.//g; |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
21
|
my @digits = split(//,$number); |
62
|
5
|
|
|
|
|
10
|
my $sum = 0; |
63
|
5
|
|
|
|
|
16
|
for (my $i = 0; $i <= $#digits; $i++) { |
64
|
50
|
|
|
|
|
101
|
$sum += $weight[$i] * $digits[$i]; |
65
|
|
|
|
|
|
|
} |
66
|
5
|
|
|
|
|
8
|
$sum %= 11; |
67
|
5
|
50
|
|
|
|
40
|
return $sum == 0 ? 0 : ($sum == 1 ? '' : 11 - $sum); |
|
|
50
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} # _compute_checkdigit() |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Preloaded methods go here. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |