line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::DK::Phonenumber; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
23207
|
use strict; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
364
|
|
4
|
11
|
|
|
11
|
|
55
|
use warnings; |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
407
|
|
5
|
11
|
|
|
11
|
|
56
|
use vars qw($VERSION @EXPORT_OK); |
|
11
|
|
|
|
|
13
|
|
|
11
|
|
|
|
|
636
|
|
6
|
11
|
|
|
11
|
|
52
|
use Carp qw(croak); |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
723
|
|
7
|
11
|
|
|
11
|
|
62
|
use base qw(Exporter); |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
1069
|
|
8
|
11
|
|
|
11
|
|
294
|
use 5.008; |
|
11
|
|
|
|
|
44
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.10'; |
11
|
|
|
|
|
|
|
@EXPORT_OK |
12
|
|
|
|
|
|
|
= qw(validate render generate validate_template TRUE FALSE DK_PREFIX DEFAULT_TEMPLATE); |
13
|
|
|
|
|
|
|
|
14
|
11
|
|
|
11
|
|
54
|
use constant TRUE => 1; |
|
11
|
|
|
|
|
41
|
|
|
11
|
|
|
|
|
840
|
|
15
|
11
|
|
|
11
|
|
51
|
use constant FALSE => 0; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
545
|
|
16
|
11
|
|
|
11
|
|
83
|
use constant DK_PREFIX => '+45'; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
595
|
|
17
|
11
|
|
|
11
|
|
60
|
use constant DIGITS => 8; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
696
|
|
18
|
11
|
|
|
11
|
|
49
|
use constant DEFAULT_TEMPLATE => DK_PREFIX . ' %0' . DIGITS . 'd'; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
530
|
|
19
|
11
|
|
|
11
|
|
47
|
use constant SEED => 99999999; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
8121
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub validate { |
22
|
81
|
|
|
81
|
1
|
21209
|
my ( $self, $phonenumber ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
81
|
50
|
|
|
|
213
|
if ( not ref $self ) { |
25
|
81
|
|
|
|
|
85
|
$phonenumber = $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
81
|
|
|
|
|
236
|
$phonenumber =~ s/\s//sxmg; |
29
|
|
|
|
|
|
|
|
30
|
81
|
100
|
|
|
|
331
|
if ($phonenumber =~ m{ |
31
|
|
|
|
|
|
|
\A( |
32
|
|
|
|
|
|
|
(?:[+])(?:45)(?:\d{8})| #+4512345678 |
33
|
|
|
|
|
|
|
(?:45)(?:\d{8})| #4512345678 |
34
|
|
|
|
|
|
|
(?:\d{8}) #12345678 |
35
|
|
|
|
|
|
|
)\z}sgmx |
36
|
|
|
|
|
|
|
) |
37
|
|
|
|
|
|
|
{ |
38
|
37
|
|
|
|
|
141
|
return TRUE; |
39
|
|
|
|
|
|
|
} else { |
40
|
44
|
|
|
|
|
163
|
return FALSE; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub render { |
45
|
116
|
|
|
116
|
1
|
1108
|
my ( $self, $phonenumber, $template ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
116
|
100
|
100
|
|
|
358
|
if ( $self =~ m/\A[\D]+\b/smx and not ref $self ) { |
|
|
100
|
|
|
|
|
|
48
|
2
|
|
|
|
|
4
|
$self = undef; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} elsif ( not ref $self ) { |
51
|
110
|
|
|
|
|
70
|
$template = $phonenumber; |
52
|
110
|
|
|
|
|
84
|
$phonenumber = $self; |
53
|
110
|
|
|
|
|
93
|
$self = undef; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} else { |
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
5
|
if ($template) { |
58
|
1
|
50
|
|
|
|
3
|
if ( ref $self ) { |
59
|
1
|
|
|
|
|
1
|
$self->validate_template($template); |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
0
|
Class::Business::DK::Phonenumber::validate_template( |
62
|
|
|
|
|
|
|
$template); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} else { |
65
|
3
|
|
50
|
|
|
7
|
$template = $self->{template} || DEFAULT_TEMPLATE; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
4
|
50
|
|
|
|
6
|
if ( not $phonenumber ) { |
69
|
4
|
|
|
|
|
4
|
$phonenumber = $self->{phonenumber}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
116
|
|
|
|
|
127
|
$phonenumber =~ s/\s//sxmg; |
74
|
|
|
|
|
|
|
|
75
|
116
|
|
|
|
|
467
|
my @subs = $template =~ m/%(\d)+d/sxmg; |
76
|
|
|
|
|
|
|
|
77
|
116
|
|
|
|
|
111
|
my $sum = 0; |
78
|
116
|
|
|
|
|
87
|
my @phonesplit = (); |
79
|
116
|
|
|
|
|
84
|
my $phonetmp = $phonenumber; |
80
|
|
|
|
|
|
|
|
81
|
116
|
|
|
|
|
112
|
foreach my $sub (@subs) { |
82
|
443
|
|
|
|
|
342
|
$sum += $sub; |
83
|
443
|
|
|
|
|
522
|
push @phonesplit, substr $phonetmp, 0, $sub, q{}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
116
|
|
|
|
|
244
|
my $output = sprintf $template, @phonesplit; |
87
|
|
|
|
|
|
|
|
88
|
116
|
|
|
|
|
536
|
return $output; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub generate { |
92
|
4
|
|
|
4
|
1
|
2649
|
my ( $self, $amount, $template ) = @_; |
93
|
|
|
|
|
|
|
|
94
|
4
|
100
|
|
|
|
9
|
if ( not $amount ) { |
95
|
1
|
|
|
|
|
1
|
$amount = 1; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
4
|
100
|
|
|
|
7
|
if ( not $template ) { |
99
|
2
|
|
|
|
|
2
|
$template = DEFAULT_TEMPLATE; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
3
|
my %phonenumbers; |
103
|
4
|
|
|
|
|
12
|
while ( keys %phonenumbers < $amount ) { |
104
|
105
|
50
|
|
|
|
107
|
if ( ref $self ) { |
105
|
0
|
|
|
|
|
0
|
$phonenumbers{ $self->_generate($template) }++; |
106
|
|
|
|
|
|
|
} else { |
107
|
105
|
|
|
|
|
93
|
$phonenumbers{ _generate($template) }++; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
|
|
34
|
my @phonenumbers = keys %phonenumbers; |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
82
|
return @phonenumbers; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _generate { |
117
|
105
|
|
|
105
|
|
84
|
my ( $self, $template ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
105
|
|
|
|
|
132
|
my $random_phone = int rand SEED; |
120
|
105
|
|
|
|
|
134
|
my $phonenumber = sprintf '%.08d', $random_phone; |
121
|
|
|
|
|
|
|
|
122
|
105
|
50
|
|
|
|
102
|
if ( ref $self ) { |
123
|
0
|
|
|
|
|
0
|
return $self->render( $phonenumber, $template ); |
124
|
|
|
|
|
|
|
} else { |
125
|
105
|
|
|
|
|
68
|
$template = $self; |
126
|
|
|
|
|
|
|
|
127
|
105
|
|
|
|
|
104
|
return render( $phonenumber, $template ); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub validate_template { |
132
|
16
|
|
|
16
|
1
|
27
|
my ( $self, $template ) = @_; |
133
|
|
|
|
|
|
|
|
134
|
16
|
|
|
|
|
77
|
my @digits = $template =~ m/%(\d)+d/sxmg; |
135
|
|
|
|
|
|
|
|
136
|
16
|
|
|
|
|
20
|
my $sum = 0; |
137
|
16
|
|
|
|
|
30
|
foreach my $digit (@digits) { |
138
|
25
|
|
|
|
|
38
|
$sum += $digit; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
16
|
100
|
|
|
|
41
|
if ( $sum == DIGITS ) { |
142
|
8
|
|
|
|
|
35
|
return TRUE; |
143
|
|
|
|
|
|
|
} else { |
144
|
8
|
|
|
|
|
33
|
return FALSE; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |