line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Random::NL; |
2
|
1
|
|
|
1
|
|
56930
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Tools for generating random Dutch numbers |
6
|
|
|
|
|
|
|
our $VERSION = '1.6'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
9
|
1
|
|
|
1
|
|
9
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
631
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @_export_person = qw(generate_bsn); |
13
|
|
|
|
|
|
|
my @_export_kvk = qw(generate_kvk generate_rsin generate_vestigingsnummer); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = (@_export_person, @_export_kvk); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
18
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
19
|
|
|
|
|
|
|
person => \@_export_person, |
20
|
|
|
|
|
|
|
company => \@_export_kvk, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub generate_bsn { |
24
|
2
|
|
|
2
|
1
|
1225
|
my $begin = shift; |
25
|
2
|
|
|
|
|
5
|
my @bsn = _generate_number_set(9, $begin); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# A BSN cannot start with a 00 |
28
|
2
|
|
33
|
|
|
6
|
while ($bsn[0] == 0 && $bsn[1] == 0) { |
29
|
0
|
|
|
|
|
0
|
$bsn[1] = int(rand(10)); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
3
|
@bsn = reverse(@bsn); |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
3
|
my $sum = 0; |
35
|
2
|
|
|
|
|
3
|
foreach my $i (reverse(1..8)) { |
36
|
16
|
|
|
|
|
31
|
$sum += (($i + 1) * $bsn[$i]); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
3
|
my $last_number = $sum % 11; |
40
|
|
|
|
|
|
|
# if the last number is 10, we have an invalid number |
41
|
2
|
50
|
|
|
|
15
|
return generate_bsn($begin) if $last_number > 9; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
2
|
@bsn = reverse(@bsn); |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
3
|
$bsn[-1] = $last_number; |
46
|
2
|
|
|
|
|
10
|
return join("", @bsn); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub generate_kvk { |
50
|
4
|
|
|
4
|
1
|
1581
|
my $begin = shift; |
51
|
4
|
|
|
|
|
6
|
my @kvk = _generate_number_set(9, 0, $begin); |
52
|
4
|
|
|
|
|
7
|
$kvk[0] = 0; # we always start with a 0 |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
6
|
@kvk = _get_last_number(@kvk); |
55
|
4
|
100
|
|
|
|
7
|
if (@kvk) { |
56
|
2
|
|
|
|
|
2
|
shift @kvk; |
57
|
2
|
|
|
|
|
11
|
return join("", @kvk); |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
6
|
return generate_kvk($begin); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub generate_rsin { |
63
|
2
|
|
|
2
|
1
|
1207
|
my $begin = shift; |
64
|
2
|
|
|
|
|
5
|
my @rsin = _generate_number_set(9, $begin); |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
6
|
@rsin = _get_last_number(@rsin); |
67
|
2
|
50
|
|
|
|
12
|
return join("", @rsin) if @rsin; |
68
|
0
|
|
|
|
|
0
|
return generate_rsin($begin); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _get_last_number { |
72
|
6
|
|
|
6
|
|
20
|
my @set = @_; |
73
|
|
|
|
|
|
|
|
74
|
6
|
|
|
|
|
7
|
@set = reverse(@set); |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
9
|
my $sum = 0; |
77
|
6
|
|
|
|
|
9
|
foreach my $i (reverse(1..8)) { |
78
|
48
|
|
|
|
|
56
|
$sum += (($i + 1) * $set[$i]); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
6
|
|
|
|
|
8
|
my $left = $sum % 11; |
82
|
6
|
|
|
|
|
8
|
my $last_number = abs($left - 11); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# if the last number is 10, we have an invalid number |
85
|
6
|
100
|
|
|
|
11
|
return if $last_number > 9; |
86
|
|
|
|
|
|
|
|
87
|
4
|
|
|
|
|
5
|
$set[0] = $last_number; |
88
|
4
|
|
|
|
|
11
|
return reverse(@set); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _generate_number_set { |
92
|
10
|
|
|
10
|
|
16
|
my ($max, @begin) = @_; |
93
|
10
|
|
|
|
|
14
|
my @number; |
94
|
10
|
|
|
|
|
15
|
foreach (@begin) { |
95
|
14
|
|
|
|
|
17
|
eval { _starts_with(\@number, $_) }; |
|
14
|
|
|
|
|
21
|
|
96
|
14
|
50
|
|
|
|
25
|
croak "$@" if $@; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
10
|
|
|
|
|
18
|
while(@number < $max) { |
100
|
86
|
|
|
|
|
168
|
push(@number, int(rand(10))); |
101
|
|
|
|
|
|
|
} |
102
|
10
|
|
|
|
|
31
|
return @number; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub generate_vestigingsnummer { |
106
|
2
|
|
|
2
|
1
|
1555
|
my $begin = shift; |
107
|
2
|
|
|
|
|
5
|
return join("", _generate_number_set(12, $begin)); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _starts_with { |
111
|
17
|
|
|
17
|
|
2174
|
my ($ref, $begin) = @_; |
112
|
|
|
|
|
|
|
|
113
|
17
|
100
|
|
|
|
35
|
if (defined $begin) { |
114
|
13
|
100
|
|
|
|
46
|
if ($begin !~ /^[0-9]$/) { |
115
|
2
|
|
|
|
|
12
|
die("You did not provide a number", $/); |
116
|
|
|
|
|
|
|
} |
117
|
11
|
|
|
|
|
15
|
push(@$ref, $begin); |
118
|
11
|
|
|
|
|
17
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |