File Coverage

blib/lib/Business/FO/Postalcode.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 7 7 100.0
total 46 46 100.0


line stmt bran cond sub pod time code
1             package Business::FO::Postalcode;
2              
3 3     3   27122 use strict;
  3         5  
  3         82  
4 3     3   10 use warnings;
  3         4  
  3         74  
5 3     3   1209 use Class::Business::FO::Postalcode;
  3         9  
  3         110  
6 3     3   53 use 5.010; #5.10.0
  3         9  
7 3     3   12 use utf8;
  3         6  
  3         13  
8              
9             require Exporter;
10              
11             our @ISA = qw(Exporter);
12             our @EXPORT_OK = qw(get_all_data get_all_postalcodes get_all_cities get_postalcode_from_city get_city_from_postalcode validate_postalcode validate);
13              
14             our $VERSION = '0.03';
15              
16             sub get_all_data {
17 2     2 1 4029 my $validator = Class::Business::FO::Postalcode->new();
18              
19 2         7 return $validator->postal_data();
20             }
21              
22             sub get_all_postalcodes {
23 2     2 1 1399 my $validator = Class::Business::FO::Postalcode->new();
24              
25 2         12 return $validator->get_all_postalcodes();
26             }
27              
28             sub get_all_cities {
29 1     1 1 1577 my $validator = Class::Business::FO::Postalcode->new();
30              
31 1         6 return $validator->get_all_cities();
32             }
33              
34             sub get_city_from_postalcode {
35 1     1 1 3593 my $validator = Class::Business::FO::Postalcode->new();
36              
37 1         17 return $validator->get_city_from_postalcode( $_[0] );
38             }
39              
40             sub get_postalcode_from_city {
41 1     1 1 2371 my $validator = Class::Business::FO::Postalcode->new();
42              
43 1         14 return $validator->get_postalcode_from_city( $_[0] );
44             }
45              
46             sub validate {
47 1000     1000 1 1689913 return validate_postalcode( $_[0] );
48             }
49              
50             sub validate_postalcode {
51 2000     2000 1 1652006 my $validator = Class::Business::FO::Postalcode->new();
52              
53 2000         4733 return $validator->validate( $_[0] );
54             }
55              
56             1;
57              
58             =pod
59              
60             =begin HTML
61              
62            
63              
64             =end HTML
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Class::Business::FO::Postalcode - Faroe Islands postal code validator and container
71              
72             =head1 VERSION
73              
74             This documentation describes version 0.03
75              
76             =head1 SYNOPSIS
77              
78             # basic validation of string
79             use Business::FO::Postalcode qw(validate);
80              
81             if (validate($postalcode)) {
82             print "We have a valid Faroe Islands postal code\n";
83             } else {
84             warn "Not a valid Faroe Islands code\n";
85             }
86              
87              
88             # basic validation of string, using less intrusive subroutine
89             use Business::FO::Postalcode qw(validate_postalcode);
90              
91             if (validate_postalcode($postalcode)) {
92             print "We have a valid Faroe Islands postal code\n";
93             } else {
94             warn "Not a valid Faroe Islands postal code\n";
95             }
96              
97              
98             # using the untainted return value
99             use Business::FO::Postalcode qw(validate_postalcode);
100              
101             if (my $untainted = validate_postalcode($postalcode)) {
102             print "We have a valid Faroe Islands postal code: $untainted\n";
103             } else {
104             warn "Not a valid Faroe Islands postal code\n";
105             }
106              
107              
108             # All postal codes for use outside this module
109             use Business::FO::Postalcode qw(get_all_postalcodes);
110              
111             my @postalcodes = @{get_all_postalcodes()};
112              
113              
114             # All postal codes and data for use outside this module
115             use Business::FO::Postalcode qw(get_all_data);
116              
117             my $postalcodes = get_all_data();
118              
119             foreach (@{postalcodes}) {
120             printf
121             'postal code: %s city: %s street/desc: %s company: %s province: %d country: %d', split /;/, $_, 6;
122             }
123              
124             =head1 FEATURES
125              
126             =over
127              
128             =item * Providing list of Faroe Islands postal codes and related area names
129              
130             =item * Look up methods for Faroe Islands postal codes for web applications and the like
131              
132             =back
133              
134             =head1 DESCRIPTION
135              
136             This distribution is not the original resource for the included data, but simply
137             acts as a simple distribution for Perl use. The central source is monitored so this
138             distribution can contain the newest data. The monitor script (F) is
139             included in the distribution: L.
140              
141             The data are converted for inclusion in this module. You can use different extraction
142             subroutines depending on your needs:
143              
144             =over
145              
146             =item * L, to retrieve all data, data description below in L.
147              
148             =item * L, to retrieve all postal codes
149              
150             =item * L, to retieve all cities
151              
152             =item * L, to retrieve one or more postal codes from a city name
153              
154             =item * L, to retieve a city name from a postal code
155              
156             =back
157              
158             =head2 Data
159              
160             Here follows a description of the included data, based on the description from
161             the original source and the authors interpretation of the data, including
162             details on the distribution of the data.
163              
164             =head3 city name
165              
166             A non-unique, case-sensitive representation of a city name in Faroese.
167              
168             =head3 street/description
169              
170             This field is unused for this dataset.
171              
172             =head3 company name
173              
174             This field is unused for this dataset.
175              
176             =head3 province
177              
178             This field is a bit special and it's use is expected to be related to distribution
179             all entries are marked as 'False'. The data are included since they are a part of
180             the original data.
181              
182             =head3 country
183              
184             Since the original source contains data on 3 different countries:
185              
186             =over
187              
188             =item * Denmark (1)
189              
190             =item * Greenland (2)
191              
192             =item * Faroe Islands (3)
193              
194             =back
195              
196             Only the data representing Greenland has been included in this distribution, so this
197             field is always containing a '3'.
198              
199             For access to the data on Denmark or Greenland please refer to: L
200             and L respectfully.
201              
202             =head2 Encoding
203              
204             The data distributed are in Faroese and Danish for descriptions and names and these are encoded in UTF-8.
205              
206             This distribution is not the original resource for the included data, but simply
207             acts as a simple distribution for Perl use. The central source is monitored so this
208             distribution can contain the newest data. The monitor script (F) is
209             included in the distribution: L.
210              
211             The data are converted for inclusion in this module. You can use different extraction
212             subroutines depending on your needs:
213              
214             =over
215              
216             =item * L, to retrieve all data, data description below in L.
217              
218             =item * L, to retrieve all postal codes
219              
220             =item * L, to retieve all cities
221              
222             =item * L, to retrieve one or more postal codes from a city name
223              
224             =item * L, to retieve a city name from a postal code
225              
226             =back
227              
228             =head2 Data
229              
230             Here follows a description of the included data, based on the description from
231             the original source and the authors interpretation of the data, including
232             details on the distribution of the data.
233              
234             =head3 city name
235              
236             A non-unique, case-sensitive representation of a city name in Greenlandic or Danish.
237              
238             =head3 street/description
239              
240             This field is unused for this dataset.
241              
242             =head3 company name
243              
244             This field is unused for this dataset.
245              
246             =head3 province
247              
248             This field is a bit special and it's use is expected to be related to distribution
249             all entries are marked as 'False'. The data are included since they are a part of
250             the original data.
251              
252             =head3 country
253              
254             Since the original source contains data on 3 different countries:
255              
256             =over
257              
258             =item * Denmark (1)
259              
260             =item * Greenland (2)
261              
262             =item * Faroe Islands (3)
263              
264             =back
265              
266             Only the data representing Greenland has been included in this distribution, so this
267             field is always containing a '2'.
268              
269             For access to the data on Denmark or Faroe Islands please refer to: L
270             and L respectfully.
271              
272             =head2 Encoding
273              
274             The data distributed are in Greenlandic and Danish for descriptions and names and these are encoded in UTF-8.
275              
276             =head1 SUBROUTINES AND METHODS
277              
278             =head2 validate
279              
280             A simple validator for Faroese postal codes.
281              
282             Takes a string representing a possible Faroese postal code and returns either
283             B<1> or B<0> indicating either validity or invalidity.
284              
285             my $rv = validate(100);
286              
287             if ($rv == 1) {
288             print "We have a valid Faroese postal code\n";
289             } ($rv == 0) {
290             print "Not a valid Faroese postal code\n";
291             }
292              
293             =head2 validate_postalcode
294              
295             A less intrusive subroutine for import. Acts as a wrapper of L.
296              
297             my $rv = validate_postalcode(100);
298              
299             if ($rv) {
300             print "We have a valid Faroese postal code\n";
301             } else {
302             print "Not a valid Faroese postal code\n";
303             }
304              
305             =head2 get_all_data
306              
307             Returns a reference to a a list of strings, separated by tab characters. See
308             L for a description of the fields.
309              
310             use Business::FO::Postalcode qw(get_all_data);
311              
312             my $postalcodes = get_all_data();
313              
314             foreach (@{postalcodes}) {
315             printf
316             'postalcode: %s city: %s street/desc: %s company: %s province: %d country: %d', split /\t/, $_, 6;
317             }
318              
319             =head2 get_all_postalcodes
320              
321             Takes no parameters.
322              
323             Returns a reference to an array containing all valid Danish postal codes
324              
325             use Business::FO::Postalcode qw(get_all_postalcodes);
326              
327             my $postalcodes = get_all_postalcodes;
328              
329             foreach my $postalcode (@{$postalcodes}) { ... }
330              
331             =head2 get_all_cities
332              
333             Takes no parameters.
334              
335             Returns a reference to an array containing all Danish city names having a postal code.
336              
337             use Business::FO::Postalcode qw(get_all_cities);
338              
339             my $cities = get_all_cities;
340              
341             foreach my $city (@{$cities}) { ... }
342              
343             Please note that this data source used in this distribution by no means is authorative
344             when it comes to cities located in Denmark, it might have all cities listed, but
345             unfortunately also other post distribution data.
346              
347             =head2 get_city_from_postalcode
348              
349             Takes a string representing a Danish postal code.
350              
351             Returns a single string representing the related city name or an empty string indicating nothing was found.
352              
353             use Business::FO::Postalcode qw(get_city_from_postalcode);
354              
355             my $zipcode = '100';
356              
357             my $city = get_city_from_postalcode($zipcode);
358              
359             if ($city) {
360             print "We found a city for $zipcode\n";
361             } else {
362             warn "No city found for $zipcode";
363             }
364              
365             =head2 get_postalcode_from_city
366              
367             Takes a string representing a Faroese city name.
368              
369             Returns a reference to an array containing zero or more postal codes related to that city name. Zero indicates nothing was found.
370              
371             Please note that city names are not unique, hence the possibility of a list of postal codes.
372              
373             use Business::FO::Postalcode qw(get_postalcode_from_city);
374              
375             my $city = 'Tórshavn';
376              
377             my $postalcodes = get_postalcode_from_city($city);
378              
379             if (scalar @{$postalcodes} == 1) {
380             print "$city is unique\n";
381             } elsif (scalar @{$postalcodes} > 1) {
382             warn "$city is NOT unique\n";
383             } else {
384             die "$city not found\n";
385             }
386              
387             =head1 DIAGNOSTICS
388              
389             There are not special diagnostics apart from the ones related to the different
390             subroutines.
391              
392             =head1 CONFIGURATION AND ENVIRONMENT
393              
394             This distribution requires no special configuration or environment.
395              
396             =head1 DEPENDENCIES
397              
398             =over
399              
400             =item * L (core)
401              
402             =item * L (core)
403              
404             =item * L
405              
406             =item * L
407              
408             =item * L
409              
410             =item * L
411              
412             =back
413              
414             =head2 TEST
415              
416             Please note that the above list does not reflect requirements for:
417              
418             =over
419              
420             =item * Additional components in this distribution, see F. Additional
421             components list own requirements
422              
423             =item * Test and build system, please see: F for details
424              
425             =back
426              
427             =head1 BUGS AND LIMITATIONS
428              
429             There are no known bugs at this time.
430              
431             The data source used in this distribution by no means is authorative when it
432             comes to cities located in Faroe Islands, it might have all cities listed, but
433             unfortunately also other post distribution data.
434              
435             =head1 BUG REPORTING
436              
437             Please report issues via CPAN RT:
438              
439             =over
440              
441             =item * Web (RT): L
442              
443             =item * Web (Github): L
444              
445             =item * Email (RT): L
446              
447             =back
448              
449             =head1 SEE ALSO
450              
451             =over
452              
453             =item L
454              
455             =item L
456              
457             =back
458              
459             =head1 MOTIVATION
460              
461             Postdanmark the largest danish postal and formerly stateowned postal service, maintain the
462             postalcode mapping for Greenland and the Faroe Islands. Since I am using this resource to
463             maintain the danish postalcodes I decided to release distributions of these two other countries.
464              
465             =head1 AUTHOR
466              
467             Jonas B. Nielsen, (jonasbn) - C<< >>
468              
469             =head1 COPYRIGHT
470              
471             Business-FO-Postalcode is (C) by Jonas B. Nielsen, (jonasbn) 2014-2015
472              
473             Business-FO-Postalcode is released under the Artistic License 2.0
474              
475             =cut