line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M10_011; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
7
|
use integer; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
31
|
use version; our $VERSION = 'v1.3.5'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
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
|
|
|
6
|
my $class = ref($proto) || $proto; |
16
|
1
|
|
|
|
|
3
|
my $self = bless({}, $class); |
17
|
1
|
|
|
|
|
8
|
$self->{type} = lc($type); |
18
|
1
|
|
|
|
|
6
|
return $self; |
19
|
|
|
|
|
|
|
} # new() |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_valid { |
22
|
2
|
|
|
2
|
1
|
9
|
my ($self,$number) = @_; |
23
|
2
|
50
|
|
|
|
13
|
if ($number =~ /^(.*)([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
|
98
|
my ($self,$number) = @_; |
31
|
1
|
|
|
|
|
3
|
my $cd = $self->_compute_checkdigit($number); |
32
|
1
|
50
|
|
|
|
3
|
if ($cd != -1) { |
33
|
1
|
|
|
|
|
7
|
return $number . $cd; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
0
|
return ''; |
36
|
|
|
|
|
|
|
} # complete() |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub basenumber { |
39
|
1
|
|
|
1
|
1
|
3
|
my ($self,$number) = @_; |
40
|
1
|
50
|
|
|
|
8
|
if ($number =~ /^(.*)([0-9])$/) { |
41
|
1
|
50
|
|
|
|
4
|
return $1 if ($2 == $self->_compute_checkdigit($1)); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
0
|
return ''; |
44
|
|
|
|
|
|
|
} # basenumber() |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub checkdigit { |
47
|
1
|
|
|
1
|
1
|
6
|
my ($self,$number) = @_; |
48
|
1
|
50
|
|
|
|
7
|
if ($number =~ /^(.*)([0-9])$/) { |
49
|
1
|
50
|
|
|
|
3
|
return $2 if ($2 == $self->_compute_checkdigit($1)); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
0
|
return ''; |
52
|
|
|
|
|
|
|
} # checkdigit() |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _compute_checkdigit { |
55
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
56
|
5
|
|
|
|
|
10
|
my $number = shift; |
57
|
5
|
|
|
|
|
28
|
$number =~ s/\s//g; |
58
|
5
|
|
|
|
|
16
|
$number =~ s/^1z//i; |
59
|
5
|
|
|
|
|
12
|
$number =~ y/A-Za-z/2-90-90-72-90-90-7/; |
60
|
5
|
50
|
|
|
|
20
|
if ($number =~ /^([0-9]*)$/) { |
61
|
5
|
|
|
|
|
26
|
my @digits = split(//,$number); |
62
|
5
|
|
|
|
|
7
|
my $even = 0; |
63
|
5
|
|
|
|
|
9
|
my $sum = 0; |
64
|
5
|
|
|
|
|
11
|
foreach my $digit (@digits) { |
65
|
75
|
|
|
|
|
106
|
$sum += $digit; |
66
|
75
|
100
|
|
|
|
120
|
$sum += $digit if ($even); |
67
|
75
|
|
|
|
|
111
|
$even = not $even; |
68
|
|
|
|
|
|
|
} |
69
|
5
|
|
|
|
|
35
|
return (10 - $sum % 10) % 10; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
return -1; |
72
|
|
|
|
|
|
|
} # _compute_checkdigit() |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Preloaded methods go here. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |