line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Business::DK::CPR; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
439783
|
use strict; |
|
4
|
|
|
|
|
45
|
|
|
4
|
|
|
|
|
194
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
129
|
|
5
|
4
|
|
|
4
|
|
2912
|
use Class::InsideOut qw( private register id ); |
|
4
|
|
|
|
|
30601
|
|
|
4
|
|
|
|
|
44
|
|
6
|
4
|
|
|
4
|
|
579
|
use Carp qw(croak); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
184
|
|
7
|
4
|
|
|
4
|
|
1159
|
use English qw(-no_match_vars); |
|
4
|
|
|
|
|
8177
|
|
|
4
|
|
|
|
|
34
|
|
8
|
4
|
|
|
4
|
|
1516
|
use 5.012; #5.12.0 |
|
4
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
2168
|
use Business::DK::CPR qw(validate1968 validate2007); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
2270
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
private number => my %number; # read-only accessor: number() |
15
|
|
|
|
|
|
|
private gender => my %gender; # read-only accessor: gender() |
16
|
|
|
|
|
|
|
private algorithm => my %algorithm; # read-only accessor: algorithm() |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
6
|
|
|
6
|
1
|
662
|
my ( $class, $number ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
6
|
100
|
|
|
|
25
|
if (not $number) { |
22
|
1
|
|
|
|
|
14
|
croak 'You must provide a CPR number'; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
## no critic (Variables::ProhibitUnusedVariables) |
26
|
5
|
|
|
|
|
16
|
my $self = \( my $scalar ); |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
13
|
bless $self, $class; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
26
|
register($self); |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
119
|
$self->set_number($number); |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
16
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## no critic (Subroutines::RequireFinalReturn) |
38
|
1
|
|
|
1
|
1
|
32
|
sub number { $number{ id $_[0] } } |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
1
|
30
|
sub get_number { $number{ id $_[0] } } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set_number { |
43
|
8
|
|
|
8
|
1
|
99
|
my ( $self, $unvalidated_cpr ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
14
|
my $rv = 0; |
46
|
8
|
|
|
|
|
15
|
my @algorithms; |
47
|
|
|
|
|
|
|
|
48
|
8
|
100
|
|
|
|
25
|
if ($unvalidated_cpr) { |
49
|
7
|
|
|
|
|
15
|
eval { $rv = validate1968($unvalidated_cpr); 1; }; |
|
7
|
|
|
|
|
27
|
|
|
6
|
|
|
|
|
13
|
|
50
|
|
|
|
|
|
|
|
51
|
7
|
50
|
66
|
|
|
497
|
if ( $rv && $rv % 2 ) { |
|
|
100
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
push @algorithms, '1968'; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ($rv) { |
55
|
5
|
|
|
|
|
16
|
push @algorithms, '1968'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
7
|
|
|
|
|
11
|
eval { $rv = validate2007($unvalidated_cpr); 1; }; |
|
7
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
15
|
|
59
|
|
|
|
|
|
|
|
60
|
7
|
50
|
66
|
|
|
464
|
if ( $rv && $rv % 2 ) { |
|
|
100
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
push @algorithms, '2007'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($rv) { |
64
|
5
|
|
|
|
|
12
|
push @algorithms, '2007'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
7
|
100
|
100
|
|
|
31
|
if ( $EVAL_ERROR or not $rv ) { |
68
|
2
|
|
|
|
|
17
|
croak 'Invalid CPR number parameter'; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
|
|
|
|
|
|
|
73
|
5
|
|
|
|
|
25
|
$number{ id $self } = $unvalidated_cpr; |
74
|
5
|
|
|
|
|
15
|
$gender{ id $self } = $rv; |
75
|
5
|
|
|
|
|
120
|
$algorithm{ id $self } = ( join ', ', @algorithms ); |
76
|
|
|
|
|
|
|
|
77
|
5
|
|
|
|
|
20
|
return 1; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
1
|
|
|
|
|
16
|
croak 'You must provide a CPR number'; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
1
|
|
sub gender { $gender{ id $_[0] } } |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
1
|
|
sub get_gender { $gender{ id $_[0] } } |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
1
|
|
sub algorithm { $algorithm{ id $_[0] } } |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
1
|
|
sub get_algorithm { $algorithm{ id $_[0] } } |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=pod |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Class::Business::DK::CPR - Danish CPR number class |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 VERSION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The documentation describes version 0.17 of Class::Business::DK::CPR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Class::Business::DK::CPR; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $cpr = Class::Business::DK::CPR->new(1501729473); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is an OOP implementation for handling Danish CPR numbers. The class gives you an CPR object, which is validated according to the CPR specification, see: |
116
|
|
|
|
|
|
|
L<Business::DK::CPR>. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SUBROUTINES AND METHODS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 new |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This is the constructor, it takes a single mandatory parameter, which should be |
123
|
|
|
|
|
|
|
a valid CPR number, if the parameter provided is not valid, the constructor |
124
|
|
|
|
|
|
|
dies. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 get_number |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This method/accessor returns the CPR number associated with the object. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 number |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Alias for the L</get_number> accessor, see above. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 set_number |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This method/mutator sets the a CPR number for a given CPR object, it takes a |
137
|
|
|
|
|
|
|
single mandatory parameter, which should be a valid CPR number, returns true (1) |
138
|
|
|
|
|
|
|
upon success else it dies. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 algorithm |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Accessor returning a string representing what algorithms used to validate the CPR object. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 get_algorithm |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
See L</algorithm> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 gender |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Accessor returning an integer representing the gender indicated by the CPR object. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * 1, male |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * 1, female |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 get_gender |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
See L</gender> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * You must provide a CPR number, thrown by L</set_number> and L</new> if |
169
|
|
|
|
|
|
|
no argument is provided. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * Invalid CPR number parameter, thrown by L</new> and L</set_number> if |
172
|
|
|
|
|
|
|
the provided argument is not a valid CPR number. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The module requires no special configuration or environment to run. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * L<Class::InsideOut> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * L<Business::DK::CPR> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=back |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The module has no known incompatibilities. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The module has no known bugs or limitations |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 TEST AND QUALITY |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Coverage of the test suite is at 98.3% |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 TODO |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=over |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * Please refer to the TODO file |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=back |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 SEE ALSO |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * L<Business::DK::CPR> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=back |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 BUG REPORTING |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Please report issue via GitHub |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=over |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item * L<GitHub Issues|https://github.com/jonasbn/perl-business-dk-cpr/issues> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=back |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Alternatively report issues via CPAN RT: |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-DK-CPR> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
or by sending mail to |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=over |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item * C<bug-Business-DK-CPR@rt.cpan.org> |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=back |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 AUTHOR |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=over |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item * Jonas B., (jonasbn) - C<< <jonasbn@cpan.org> >> |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=back |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 COPYRIGHT |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Business-DK-CPR and related is (C) by Jonas B., (jonasbn) 2006-2020 |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 LICENSE |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Business-DK-CPR and related is released under the Artistic License 2.0 |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=cut |