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