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