| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Number::Phone::AU; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
602167
|
use Carp; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
231
|
|
|
4
|
3
|
|
|
3
|
|
2674
|
use Mouse; |
|
|
3
|
|
|
|
|
122723
|
|
|
|
3
|
|
|
|
|
18
|
|
|
5
|
3
|
|
|
3
|
|
1292
|
use Mouse::Util::TypeConstraints; |
|
|
3
|
|
|
|
|
99
|
|
|
|
3
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
subtype 'Number::Phone::AU::StateCode' |
|
8
|
|
|
|
|
|
|
=> as 'Str' |
|
9
|
|
|
|
|
|
|
=> where { length $_ == 2 }; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
subtype 'Number::Phone::AU::NumericString' |
|
12
|
|
|
|
|
|
|
=> as 'Str' |
|
13
|
|
|
|
|
|
|
=> where { !/\D/ }; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'orig_number' => (is => 'rw', isa => 'Str', required => 1); |
|
16
|
|
|
|
|
|
|
has 'stripped_number' => (is => 'rw', isa => 'Number::Phone::AU::NumericString'); |
|
17
|
|
|
|
|
|
|
has 'country_code' => (is => 'rw', isa => 'Int'); |
|
18
|
|
|
|
|
|
|
has 'local_number' => (is => 'rw', isa => 'Number::Phone::AU::NumericString'); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'state_code' => |
|
21
|
|
|
|
|
|
|
is => 'rw', |
|
22
|
|
|
|
|
|
|
isa => 'Number::Phone::AU::StateCode', |
|
23
|
|
|
|
|
|
|
default => '00', |
|
24
|
|
|
|
|
|
|
; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Number::Phone::AU - Validation for Australian Phone numbers |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use Number::Phone::AU; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $valid_number = Number::Phone::AU->new( $number ); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This is a module for validating Australian phone numbers. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 new |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $number = Number::Phone::AU->new( $input_number ); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Returns an object representing the $number. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub BUILDARGS { |
|
55
|
54
|
|
|
54
|
1
|
25402
|
my ( $class, $number ) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
54
|
100
|
|
|
|
170
|
croak "The number is undefined" if !defined $number; |
|
58
|
53
|
100
|
|
|
|
122
|
croak "The number is a reference" if ref $number; |
|
59
|
|
|
|
|
|
|
|
|
60
|
52
|
|
|
|
|
466
|
return { orig_number => $number }; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub BUILD { |
|
64
|
52
|
|
|
52
|
1
|
63
|
my $self = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
52
|
|
|
|
|
125
|
my $number = $self->orig_number; |
|
67
|
|
|
|
|
|
|
|
|
68
|
52
|
|
|
|
|
199
|
$number =~ s/\D//g; |
|
69
|
52
|
|
|
|
|
145
|
$self->stripped_number( $number ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# strip off country codes |
|
72
|
52
|
|
|
|
|
91
|
$number =~ s/^(61|672)//; |
|
73
|
52
|
|
100
|
|
|
313
|
$self->country_code( $1 || '61' ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
52
|
100
|
|
|
|
207
|
if ( length $number == 9 ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
76
|
9
|
|
|
|
|
40
|
$self->state_code( 0 . substr( $number, 0, 1, '' ) ); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
elsif ( length $number == 10 ) { |
|
79
|
12
|
|
|
|
|
47
|
$self->state_code( substr( $number, 0, 2, '') ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
elsif( $number =~ s/^(13|18)// ) { |
|
82
|
11
|
|
|
|
|
33
|
$self->state_code( $1 ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
52
|
|
|
|
|
139
|
$self->local_number($number); |
|
86
|
|
|
|
|
|
|
|
|
87
|
52
|
|
|
|
|
136
|
return; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 is_valid_contact |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $is_valid = $number->is_valid_contact; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Returns true if the $number is a valid Australian contact number for a |
|
96
|
|
|
|
|
|
|
business or person. Toll free numbers like 1300 and 1800 are valid as they |
|
97
|
|
|
|
|
|
|
may be a business contact. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Emergency numbers and special codes are invalid. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub is_valid_contact { |
|
104
|
51
|
|
|
51
|
1
|
72
|
my $self = shift; |
|
105
|
|
|
|
|
|
|
|
|
106
|
51
|
100
|
|
|
|
164
|
return $self->_is_valid_672 if $self->country_code == 672; |
|
107
|
49
|
100
|
|
|
|
136
|
return $self->_is_valid_13x if $self->state_code == 13; |
|
108
|
43
|
100
|
|
|
|
120
|
return $self->_is_valid_18x if $self->state_code == 18; |
|
109
|
|
|
|
|
|
|
|
|
110
|
35
|
100
|
|
|
|
145
|
return unless length $self->local_number == 8; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# At this point we have a 9 or 10 digit clean number |
|
113
|
19
|
|
|
|
|
36
|
return $self->_has_valid_state_code; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# This assumes a sanitized number |
|
118
|
|
|
|
|
|
|
sub _is_valid_672 { |
|
119
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
|
120
|
2
|
|
|
|
|
12
|
return length $self->local_number == 6; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# This assumes a sanitized number |
|
125
|
|
|
|
|
|
|
sub _is_valid_13x { |
|
126
|
6
|
|
|
6
|
|
8
|
my $self = shift; |
|
127
|
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
8
|
$DB::single = 1; |
|
129
|
6
|
|
|
|
|
14
|
my $number = $self->local_number; |
|
130
|
6
|
100
|
|
|
|
45
|
if ( $number =~ m/^00/ ) { |
|
131
|
2
|
|
|
|
|
11
|
return length $number == 8; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
else { |
|
134
|
4
|
|
|
|
|
23
|
return length $number == 4; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# This assumes a sanitized number |
|
140
|
|
|
|
|
|
|
sub _is_valid_18x { |
|
141
|
8
|
|
|
8
|
|
11
|
my $self = shift; |
|
142
|
|
|
|
|
|
|
|
|
143
|
8
|
|
|
|
|
15
|
my $number = $self->local_number; |
|
144
|
8
|
100
|
|
|
|
29
|
if( $number =~ m/^00/ ) { |
|
|
|
100
|
|
|
|
|
|
|
145
|
3
|
|
|
|
|
14
|
return length $number == 8; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
elsif( $number =~ m/^0/ ) { |
|
148
|
4
|
|
|
|
|
19
|
return length $number == 5; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
else { |
|
151
|
1
|
|
|
|
|
4
|
return; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# This assumes a sanitized 9 or 10 digit number |
|
157
|
|
|
|
|
|
|
my @valid_state_codes = (2,3,4,5,7,8); |
|
158
|
|
|
|
|
|
|
sub _has_valid_state_code { |
|
159
|
19
|
|
|
19
|
|
27
|
my $self = shift; |
|
160
|
|
|
|
|
|
|
|
|
161
|
19
|
100
|
|
|
|
32
|
return if $self->_is_fake; |
|
162
|
|
|
|
|
|
|
|
|
163
|
16
|
|
|
|
|
33
|
my $state_code = $self->state_code; |
|
164
|
16
|
|
|
|
|
28
|
return scalar grep { $state_code == $_ } @valid_state_codes; |
|
|
96
|
|
|
|
|
206
|
|
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _is_fake { |
|
168
|
19
|
|
|
19
|
|
21
|
my $self = shift; |
|
169
|
|
|
|
|
|
|
|
|
170
|
19
|
|
|
|
|
40
|
my $number = $self->local_number; |
|
171
|
|
|
|
|
|
|
|
|
172
|
19
|
100
|
100
|
|
|
126
|
return 1 if $self->state_code != 3 and $number =~ m/^5551/; |
|
173
|
18
|
100
|
|
|
|
52
|
return 1 if $number =~ m/^7010/; |
|
174
|
|
|
|
|
|
|
|
|
175
|
16
|
|
|
|
|
37
|
return; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 INTERFACE NOTE |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
The interface of this module differs significantly from that set forth by |
|
181
|
|
|
|
|
|
|
Number::Phone. If you're used to using that module, please read the |
|
182
|
|
|
|
|
|
|
documentation carefully. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Josh Heumann, C<< >> |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 BUGS |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
191
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
192
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 SUPPORT |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
perldoc Number::Phone::AU |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
You can also look for information at: |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=over 4 |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
L |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
L |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item * Search CPAN |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
L |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Copyright 2010 Josh Heumann. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
235
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
236
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
1; # End of Number::Phone::AU |