line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Business::FO::Postalcode; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
3674
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
69
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
66
|
|
5
|
3
|
|
|
3
|
|
12
|
use base qw(Class::Business::GL::Postalcode); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1339
|
|
6
|
3
|
|
|
3
|
|
97682
|
use 5.010; #5.10.0 |
|
3
|
|
|
|
|
8
|
|
7
|
3
|
|
|
3
|
|
14
|
use utf8; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
19
|
|
8
|
3
|
|
|
3
|
|
62
|
use Data::Handle; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
164
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION: generated by DZP::OurPkgVersion |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
17
|
use constant NUM_OF_DIGITS_IN_POSTALCODE => 3; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
512
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
2008
|
|
|
2008
|
1
|
4006
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
2008
|
|
|
|
|
3951
|
my $self = bless ({}, $class); |
18
|
|
|
|
|
|
|
|
19
|
2008
|
|
|
|
|
6282
|
my $handle = Data::Handle->new( __PACKAGE__ ); |
20
|
2008
|
|
|
|
|
553554
|
my @postal_data = $handle->getlines(); |
21
|
|
|
|
|
|
|
|
22
|
2008
|
|
|
|
|
397381
|
$self->postal_data(\@postal_data); |
23
|
2008
|
|
|
|
|
19027
|
$self->num_of_digits_in_postalcode(NUM_OF_DIGITS_IN_POSTALCODE); |
24
|
|
|
|
|
|
|
|
25
|
2008
|
|
|
|
|
13717
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=pod |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=encoding UTF-8 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=begin markdown |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
[![CPAN version](https://badge.fury.io/pl/Business-FO-Postalcode.svg)](http://badge.fury.io/pl/Business-FO-Postalcode) |
37
|
|
|
|
|
|
|
[![Build Status](https://travis-ci.org/jonasbn/perl-Business-FO-Postalcode.svg?branch=master)](https://travis-ci.org/jonasbn/perl-Business-FO-Postalcode.svg) |
38
|
|
|
|
|
|
|
[![Coverage Status](https://coveralls.io/repos/jonasbn/perl-Business-FO-Postalcode/badge.png)](https://coveralls.io/r/jonasbn/perl-Business-FO-Postalcode) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=end markdown |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Class::Business::FO::Postalcode - OO interface to validation and listing of Faroe Islands postal codes |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 VERSION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This documentation describes version 0.03 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# construction |
53
|
|
|
|
|
|
|
my $validator = Class::Business::FO::Postalcode->new(); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# basic validation of string |
56
|
|
|
|
|
|
|
if ($validator->validate($postalcode)) { |
57
|
|
|
|
|
|
|
print "We have a valid Faroe Islands postal code\n"; |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
warn "Not a valid Faroe Islands postal code\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# All postal codes for use outside this module |
64
|
|
|
|
|
|
|
my @postalcodes = @{$validator->get_all_postalcodes()}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
foreach (@{postalcodes}) { |
68
|
|
|
|
|
|
|
printf |
69
|
|
|
|
|
|
|
'postal code: %s city: %s street/desc: %s company: %s province: %d country: %d', split /;/, $_, 6; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 FEATURES |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item * Providing list of Faroe Islands postal codes and related area names |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item * Look up methods for Faroe Islands postal codes for web applications and the like |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Please note that this class inherits from: L, |
85
|
|
|
|
|
|
|
so most of the functionality is implmented in the parent class. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This distribution is not the original resource for the included data, but simply |
88
|
|
|
|
|
|
|
acts as a simple distribution for Perl use. The central source is monitored so this |
89
|
|
|
|
|
|
|
distribution can contain the newest data. The monitor script (F) is |
90
|
|
|
|
|
|
|
included in the distribution: L. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The data are converted for inclusion in this module. You can use different extraction |
93
|
|
|
|
|
|
|
subroutines depending on your needs: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * L, to retrieve all data, data description below in L. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * L, to retrieve all postal codes |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * L, to retieve all cities |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * L, to retrieve one or more postal codes from a city name |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * L, to retieve a city name from a postal code |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=back |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 Data |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Here follows a description of the included data, based on the description from |
112
|
|
|
|
|
|
|
the original source and the authors interpretation of the data, including |
113
|
|
|
|
|
|
|
details on the distribution of the data. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head3 city name |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
A non-unique, case-sensitive representation of a city name in Faroese or Danish. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head3 street/description |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This field is unused for this dataset. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head3 company name |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This field is unused for this dataset. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head3 province |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This field is a bit special and it's use is expected to be related to distribution |
130
|
|
|
|
|
|
|
all entries are marked as 'False'. The data are included since they are a part of |
131
|
|
|
|
|
|
|
the original data. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head3 country |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Since the original source contains data on 3 different countries: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * Denmark (1) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * Greenland (2) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * Faroe Islands (3) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Only the data representing Faroe Islands has been included in this distribution, so this |
148
|
|
|
|
|
|
|
field is always containing a '3'. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
For access to the data on Denmark or Greenland please refer to: L |
151
|
|
|
|
|
|
|
and L respectfully. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 Encoding |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The data distributed are in Faroese and Danish for descriptions and names and these are encoded in UTF-8. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SUBROUTINES AND METHODS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 new |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Basic contructor, takes no arguments. Load the dataset and returns |
162
|
|
|
|
|
|
|
a Class::Business::FO::Postalcode object. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 validate |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
A simple validator for Faroese postal codes. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Takes a string representing a possible Faroese postal code and returns either |
169
|
|
|
|
|
|
|
B<1> or B<0> indicating either validity or invalidity. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $rv = $validator->validate(100); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
if ($rv == 1) { |
176
|
|
|
|
|
|
|
print "We have a valid Faroese postal code\n"; |
177
|
|
|
|
|
|
|
} ($rv == 0) { |
178
|
|
|
|
|
|
|
print "Not a valid Faroese postal code\n"; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 get_all_postalcodes |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Takes no parameters. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Returns a reference to an array containing all valid Faroese postal codes. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $postalcodes = $validator->get_all_postalcodes; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
foreach my $postalcode (@{$postalcodes}) { ... } |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 get_all_cities |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Takes no parameters. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns a reference to an array containing all Faroese city names having a postal code. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $cities = $validator->get_all_cities; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
foreach my $city (@{$cities}) { ... } |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Please note that this data source used in this distribution by no means is authorative |
206
|
|
|
|
|
|
|
when it comes to cities located in Denmark, it might have all cities listed, but |
207
|
|
|
|
|
|
|
unfortunately also other post distribution data. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 get_city_from_postalcode |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Takes a string representing a Faroese postal code. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Returns a single string representing the related city name or an empty string indicating nothing was found. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
my $zipcode = '3900'; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
my $city = $validator->get_city_from_postalcode($zipcode); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
if ($city) { |
222
|
|
|
|
|
|
|
print "We found a city for $zipcode\n"; |
223
|
|
|
|
|
|
|
} else { |
224
|
|
|
|
|
|
|
warn "No city found for $zipcode"; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 get_postalcode_from_city |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Takes a string representing a Faroese city name. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Returns a reference to an array containing zero or more postal codes related to that city name. Zero indicates nothing was found. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Please note that city names are not unique, hence the possibility of a list of postal codes. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
my $city = 'Tórshavn'; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
my $postalcodes = $validator->get_postalcode_from_city($city); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
if (scalar @{$postalcodes} == 1) { |
242
|
|
|
|
|
|
|
print "$city is unique\n"; |
243
|
|
|
|
|
|
|
} elsif (scalar @{$postalcodes} > 1) { |
244
|
|
|
|
|
|
|
warn "$city is NOT unique\n"; |
245
|
|
|
|
|
|
|
} else { |
246
|
|
|
|
|
|
|
die "$city not found\n"; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 num_of_digits_in_postalcode |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Mutator to get/set the number of digits used to compose a Greenlandic postal code |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
my $rv = $validator->num_of_digits_in_postalcode(3); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
my $digits = $validator->num_of_digits_in_postalcode(); |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head2 postal_data |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Mutator to get/set the reference to the array comprising the main data structure |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
my $validator = Business::FO::Postalcode->new(); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
my $rv = $validator->postal_data(\@postal_data); |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
my $postal_data = $validator->postal_data(); |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
There are not special diagnostics apart from the ones related to the different |
272
|
|
|
|
|
|
|
subroutines. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This distribution requires no special configuration or environment. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=over |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=item * L (core) |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=item * L (core) |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item * L |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=item * L |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=item * L |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=back |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head2 TEST |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
Please note that the above list does not reflect requirements for: |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=over |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=item * Additional components in this distribution, see F. Additional |
301
|
|
|
|
|
|
|
components list own requirements |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item * Test and build system, please see: F for details |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=back |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
There are no known bugs at this time. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
The data source used in this distribution by no means is authorative when it |
312
|
|
|
|
|
|
|
comes to cities located in Faroe Islands, it might have all cities listed, but |
313
|
|
|
|
|
|
|
unfortunately also other post distribution data. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 BUG REPORTING |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Please report issues via CPAN RT: |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=over |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=item * Web (RT): L |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=item * Web (Github): L |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item * Email (RT): L |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=back |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head1 SEE ALSO |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=over |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=item L |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=item L |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=back |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head1 MOTIVATION |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
Postdanmark the largest danish postal and formerly stateowned postal service, maintain the |
342
|
|
|
|
|
|
|
postalcode mapping for Greenland and the Faroe Islands. Since I am using this resource to |
343
|
|
|
|
|
|
|
maintain the danish postalcodes I decided to release distributions of these two other countries. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 AUTHOR |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
Jonas B., (jonasbn) - C<< >> |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=head1 COPYRIGHT |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
Class-Business-FO-Postalcode is (C) by Jonas B., (jonasbn) 2014-2019 |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Class-Business-FO-Postalcode is released under the artistic license 2.0 |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=cut |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
__DATA__ |