line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M10_005; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
6
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
58
|
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
|
2
|
my $proto = shift; |
14
|
1
|
|
|
|
|
2
|
my $type = shift; |
15
|
1
|
|
33
|
|
|
6
|
my $class = ref($proto) || $proto; |
16
|
1
|
|
|
|
|
2
|
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
|
8
|
my ($self,$number) = @_; |
23
|
2
|
50
|
|
|
|
12
|
if ($number =~ /^([0-9 .]{11,})([0-9])$/) { |
24
|
2
|
|
|
|
|
5
|
return $2 == $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
|
|
|
|
14
|
if ($number =~ /^[0-9 .]{11,}$/) { |
32
|
1
|
|
|
|
|
4
|
return $number . $self->_compute_checkdigit($number); |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
0
|
return ''; |
35
|
|
|
|
|
|
|
} # complete() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub basenumber { |
38
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
39
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^([0-9 .]{11,})([0-9])$/) { |
40
|
1
|
50
|
|
|
|
3
|
return $1 if ($2 == $self->_compute_checkdigit($1)); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
return ''; |
43
|
|
|
|
|
|
|
} # basenumber() |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub checkdigit { |
46
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
47
|
1
|
50
|
|
|
|
7
|
if ($number =~ /^([0-9 .]{11,})([0-9])$/) { |
48
|
1
|
50
|
|
|
|
2
|
return $2 if ($2 == $self->_compute_checkdigit($1)); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
return ''; |
51
|
|
|
|
|
|
|
} # checkdigit() |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _compute_checkdigit { |
54
|
5
|
|
|
5
|
|
9
|
my $self = shift; |
55
|
5
|
|
|
|
|
10
|
my $number = shift; |
56
|
5
|
|
|
|
|
28
|
$number =~ s/[.\s]//g; |
57
|
5
|
50
|
|
|
|
17
|
if ($number =~ /^([0-9]{11})$/) { |
58
|
5
|
|
|
|
|
21
|
my @digits = split(//,$number); |
59
|
5
|
|
|
|
|
7
|
my $even = 0; |
60
|
5
|
|
|
|
|
8
|
my $sum = 0; |
61
|
5
|
|
|
|
|
15
|
for (my $i = 0; $i <= $#digits; $i++) { |
62
|
55
|
100
|
|
|
|
88
|
if ($even) { |
63
|
25
|
|
|
|
|
36
|
$sum += 9 * $digits[$i]; |
64
|
|
|
|
|
|
|
} else { |
65
|
30
|
|
|
|
|
45
|
$sum += 4 * $digits[$i]; |
66
|
|
|
|
|
|
|
} |
67
|
55
|
|
|
|
|
105
|
$even = not $even; |
68
|
|
|
|
|
|
|
} |
69
|
5
|
|
|
|
|
36
|
return (10 - $sum % 10) % 10; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
return -1; |
72
|
|
|
|
|
|
|
} # _compute_checkdigit() |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Preloaded methods go here. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |