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