File Coverage

blib/lib/Class/Business/FO/Postalcode.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 36 36 100.0


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