line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::RO::CIF; |
2
|
|
|
|
|
|
|
$Business::RO::CIF::VERSION = '0.004'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Romanian CIF validation |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
30100
|
use Moo; |
|
2
|
|
|
|
|
23141
|
|
|
2
|
|
|
|
|
12
|
|
6
|
2
|
|
|
2
|
|
2329
|
use 5.010; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
7
|
2
|
|
|
2
|
|
1133
|
use utf8; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
8
|
|
8
|
2
|
|
|
2
|
|
1123
|
use Types::Standard qw(Int ArrayRef Str); |
|
2
|
|
|
|
|
106746
|
|
|
2
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'cif' => ( |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
isa => Str, |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'errstr' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => Str, |
19
|
|
|
|
|
|
|
default => sub {''}, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'rev_key' => ( |
23
|
|
|
|
|
|
|
is => 'lazy', |
24
|
|
|
|
|
|
|
isa => ArrayRef, |
25
|
|
|
|
|
|
|
init_arg => undef, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _build_rev_key { |
29
|
9
|
|
|
9
|
|
553
|
my $self = shift; |
30
|
9
|
|
|
|
|
33
|
my @revkey = reverse split //, '753217532'; |
31
|
9
|
|
|
|
|
128
|
return \@revkey; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'checksum' => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => Int, |
37
|
|
|
|
|
|
|
init_arg => undef, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'rev_cif' => ( |
41
|
|
|
|
|
|
|
is => 'lazy', |
42
|
|
|
|
|
|
|
isa => ArrayRef, |
43
|
|
|
|
|
|
|
init_arg => undef, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _build_rev_cif { |
47
|
9
|
|
|
9
|
|
569
|
my $self = shift; |
48
|
9
|
50
|
|
|
|
21
|
if ( my $cif = $self->cif ) { |
49
|
9
|
|
|
|
|
36
|
my @revcif = reverse split //, $cif; |
50
|
9
|
|
|
|
|
122
|
$self->checksum(shift @revcif); |
51
|
9
|
|
|
|
|
860
|
return \@revcif; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
die "No CIF?"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub valid { |
59
|
10
|
|
|
10
|
1
|
3634
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
10
|
100
|
|
|
|
49
|
if ( $self->cif =~ m{[^0-9]} ) { |
62
|
1
|
|
|
|
|
5
|
$self->errstr('The input string contains invalid characters'); |
63
|
1
|
|
|
|
|
485
|
return 0; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
9
|
|
|
|
|
8
|
my @rev_cif = @{ $self->rev_cif }; |
|
9
|
|
|
|
|
187
|
|
67
|
9
|
|
|
|
|
151
|
my @rev_key = @{ $self->rev_key }; |
|
9
|
|
|
|
|
119
|
|
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
|
|
132
|
my $len = scalar @rev_cif; |
70
|
9
|
100
|
|
|
|
20
|
if ($len < 5) { |
71
|
1
|
|
|
|
|
19
|
$self->errstr('The input is too short (< 5)'); |
72
|
1
|
|
|
|
|
26
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
8
|
100
|
|
|
|
13
|
if ($len > 9) { |
75
|
1
|
|
|
|
|
16
|
$self->errstr('The input is too long (> 9)'); |
76
|
1
|
|
|
|
|
21
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
7
|
|
|
|
|
7
|
my $sum = 0; |
80
|
7
|
|
|
|
|
15
|
foreach ( 0 .. $#rev_cif ) { |
81
|
48
|
|
|
|
|
62
|
$sum += $rev_cif[$_] * $rev_key[$_]; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
7
|
|
|
|
|
11
|
my $m11 = $sum * 10 % 11; |
85
|
7
|
50
|
|
|
|
13
|
my $ctc = $m11 == 10 ? 0 : $m11; |
86
|
|
|
|
|
|
|
|
87
|
7
|
100
|
|
|
|
126
|
if ( $self->checksum == $ctc ) { |
88
|
5
|
|
|
|
|
41
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
2
|
|
|
|
|
37
|
$self->errstr('The checksum failed'); |
92
|
2
|
|
|
|
|
36
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
return |
95
|
0
|
|
|
|
|
0
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub BUILDARGS { |
98
|
10
|
|
|
10
|
1
|
5632
|
my ( $class, @args ) = @_; |
99
|
10
|
100
|
66
|
|
|
39
|
if ( @args == 1 && !ref $args[0] ) { |
100
|
1
|
|
|
|
|
4
|
$args[0] =~ s{^RO\s*}{}i; |
101
|
1
|
|
|
|
|
17
|
return { cif => $args[0] }; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
9
|
|
|
|
|
21
|
my %para = @args; |
105
|
9
|
|
|
|
|
19
|
$para{cif} =~ s{^RO\s*}{}i; |
106
|
9
|
|
|
|
|
135
|
return \%para; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |