line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::PFR; |
2
|
|
|
|
|
|
|
$Business::PFR::VERSION = '1.0.2'; |
3
|
1
|
|
|
1
|
|
55124
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: validate Russian pension fund number |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
25
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
429
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
7
|
|
|
7
|
1
|
1663
|
my ($class, %params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
7
|
|
|
|
|
9
|
my $self = {}; |
19
|
7
|
|
|
|
|
9
|
bless $self, $class; |
20
|
|
|
|
|
|
|
|
21
|
7
|
|
|
|
|
15
|
$self->{_maybe_pfr} = delete $params{value}; |
22
|
|
|
|
|
|
|
|
23
|
7
|
50
|
|
|
|
12
|
croak "Incorrect constructor usage. Stopped" if %params; |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
13
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub is_valid { |
30
|
7
|
|
|
7
|
1
|
30
|
my ($self, @params) = @_; |
31
|
|
|
|
|
|
|
|
32
|
7
|
50
|
|
|
|
13
|
croak "Incorrect usage. Stopped" if @params; |
33
|
|
|
|
|
|
|
|
34
|
7
|
50
|
|
|
|
10
|
if (not defined $self->{_is_valid}) { |
35
|
7
|
|
|
|
|
13
|
$self->{_is_valid} = $self->_check_is_valid(); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
30
|
return $self->{_is_valid}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _check_is_valid { |
42
|
7
|
|
|
7
|
|
8
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
7
|
100
|
|
|
|
11
|
return 0 if not defined $self->{_maybe_pfr}; |
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
|
|
5
|
my $is_valid; |
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
|
|
7
|
my $maybe_pfr = $self->{_maybe_pfr}; |
49
|
|
|
|
|
|
|
|
50
|
6
|
100
|
|
|
|
20
|
if ($maybe_pfr =~ /^(\d)(\d)(\d)-(\d)(\d)(\d)-(\d)(\d)(\d) (\d{2})$/a) { |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
21
|
my $sum = |
53
|
|
|
|
|
|
|
$1 * 9 |
54
|
|
|
|
|
|
|
+ $2 * 8 |
55
|
|
|
|
|
|
|
+ $3 * 7 |
56
|
|
|
|
|
|
|
+ $4 * 6 |
57
|
|
|
|
|
|
|
+ $5 * 5 |
58
|
|
|
|
|
|
|
+ $6 * 4 |
59
|
|
|
|
|
|
|
+ $7 * 3 |
60
|
|
|
|
|
|
|
+ $8 * 2 |
61
|
|
|
|
|
|
|
+ $9 * 1 |
62
|
|
|
|
|
|
|
; |
63
|
|
|
|
|
|
|
|
64
|
3
|
100
|
|
|
|
6
|
if ( $self->_get_check_digit($sum) eq $10) { |
65
|
2
|
|
|
|
|
3
|
$is_valid = 1; |
66
|
|
|
|
|
|
|
} else { |
67
|
1
|
|
|
|
|
6
|
$is_valid = 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} else { |
71
|
3
|
|
|
|
|
4
|
$is_valid = 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
6
|
|
|
|
|
7
|
return $is_valid; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _get_check_digit { |
78
|
9
|
|
|
9
|
|
2489
|
my ($self, $sum) = @_; |
79
|
|
|
|
|
|
|
|
80
|
9
|
|
|
|
|
53
|
my ($digit) = sprintf("%02d", $sum % 101) =~ /(\d{2})\z/; |
81
|
|
|
|
|
|
|
|
82
|
9
|
|
|
|
|
43
|
return $digit; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |