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