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