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