line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::CheckDigits::M11_013; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
6
|
1
|
|
|
1
|
|
5
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
32
|
use version; our $VERSION = 'v1.3.5'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
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
|
|
|
|
|
5
|
my $self = bless({}, $class); |
17
|
1
|
|
|
|
|
8
|
$self->{type} = lc($type); |
18
|
1
|
|
|
|
|
7
|
return $self; |
19
|
|
|
|
|
|
|
} # new() |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_valid { |
22
|
2
|
|
|
2
|
1
|
8
|
my ($self,$number) = @_; |
23
|
2
|
50
|
|
|
|
14
|
if ($number =~ /^([0-9]+)(\d)$/) { |
24
|
2
|
|
|
|
|
5
|
return $2 == $self->_compute_checkdigits($1); |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
0
|
return '' |
27
|
|
|
|
|
|
|
} # is_valid() |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub complete { |
30
|
1
|
|
|
1
|
1
|
97
|
my ($self,$number) = @_; |
31
|
1
|
50
|
33
|
|
|
9
|
if ($number =~ /^([0-9]+)$/ |
32
|
|
|
|
|
|
|
and (my $cd = $self->_compute_checkdigits($1)) ne '') { |
33
|
1
|
|
|
|
|
7
|
return $1 . $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]+)(\d)$/) { |
41
|
1
|
50
|
|
|
|
3
|
return $1 if ($2 == $self->_compute_checkdigits($1)); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
0
|
return ''; |
44
|
|
|
|
|
|
|
} # basenumber() |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub checkdigit { |
47
|
1
|
|
|
1
|
1
|
4
|
my ($self,$number) = @_; |
48
|
1
|
50
|
|
|
|
6
|
if ($number =~ /^([0-9]+)(\d)$/) { |
49
|
1
|
50
|
|
|
|
5
|
return $2 if ($2 == $self->_compute_checkdigits($1)); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
0
|
return ''; |
52
|
|
|
|
|
|
|
} # checkdigit() |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _compute_checkdigits { |
55
|
5
|
|
|
5
|
|
11
|
my $self = shift; |
56
|
5
|
|
|
|
|
11
|
my $number = shift; |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
19
|
my @digits = split(//,$number); |
59
|
5
|
|
|
|
|
10
|
my $len = scalar(@digits); |
60
|
5
|
|
|
|
|
8
|
my $sum = 0; |
61
|
5
|
|
|
|
|
34
|
for (my $i = $#digits; $i >= 0; $i--) { |
62
|
40
|
|
|
|
|
85
|
$sum += 2 ** ($len - $i) * $digits[$i]; |
63
|
|
|
|
|
|
|
} |
64
|
5
|
|
|
|
|
9
|
$sum %= 11; |
65
|
5
|
50
|
|
|
|
36
|
return ($sum > 9) ? 0 : $sum; |
66
|
|
|
|
|
|
|
} # _compute_checkdigit() |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Preloaded methods go here. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |