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