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