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