File Coverage

blib/lib/Image/Maps/Plot/FromPostcode.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Image::Maps::Plot::FromPostcode; # where in the world are London.pm members?
2            
3             our $VERSION = 2;
4             our $DATE = "Tue 12 Feb 2003 15:33 CET";#"Mon 28 May 09:59 2002 CET"; #"Fri 06 July 19:18 2001 BST";
5 1     1   14371 use 5.006;
  1         4  
  1         42  
6 1     1   6 use strict;
  1         2  
  1         35  
7 1     1   5 use warnings;
  1         6  
  1         46  
8            
9 1     1   6 use base "Image::Maps::Plot::FromLatLong";
  1         2  
  1         1935  
10            
11             our %locations;
12             our $ADDENTRY; # Should be object field
13            
14             =head1 NAME
15            
16             Image::Maps::Plot::FromPostcode - from postcodes plot world/regional maps in JPEG/HTML
17            
18             =head1 DESCRIPTION
19            
20             This module is a sub-class of C,
21             that uses the C module to convert postcodes to
22             latitude and longitude.
23            
24             =head1 OVER-RIDDEN METHODS
25            
26             =head2 METHOD add_entry
27            
28             A method that accepts: $name, $country, $postcode
29            
30             Looks up on MapBlast.com the supplied details, and adds them to the db.
31            
32             If an entry already exists for $name, will return C unless
33             the global scalar C<$ADDENTRY> is set to it's default value of C,
34             in which case $name will be appended with $country and $postcode.
35            
36             Does not save them to file - you must do that manually (L<"METHOD save_db">), but
37             note that you may wish to load the db before adding to it and saving.
38            
39             Incidentaly returns a reference to the new key.
40            
41             See also L.
42            
43             =cut
44            
45             sub add_entry { my ($self, $name,$country,$postcode) = (@_);
46             eval('use WWW::MapBlast 0.02;');
47             die "Can't add_entry without \$name, \$country, \$postcode "
48             unless (defined $name and defined $country and defined $postcode);
49            
50             my ($lat,$lon,$address) = WWW::MapBlast::latlon($country,$postcode);
51             $lat = 11111111 if not defined $lat or $lat eq '';
52             $lon = 11111111 if not defined $lon or $lon eq '';
53             if (not defined $address or $address eq ''){
54             $address = "$postcode $country - MapBlast.com didn't know"
55             }
56            
57             if (exists $locations{$name} ){
58             if ($ADDENTRY ne 'MULTIPLE'){
59             warn "Not adding duplicate entry for $name at $postcode, $country.\n" if $self->{chat};
60             return undef;
61             }
62             $name .= " ($postcode $country)";
63             }
64            
65             $locations{$name} = {
66             PLACE=>$address,
67             LAT=>$lat,
68             LON=>$lon,
69             };
70            
71             return \$locations{$name};
72             }
73            
74            
75            
76             =head2 &remove_entry
77            
78             A subroutine, not a method, that accepts the name field of the entry in the db, and returns
79             C<1> on success, C if no such entry exists.
80            
81             =cut
82            
83             sub remove_entry { my ($name) = (shift);
84             return undef if not exists $locations{$name};
85             delete $locations{$name};
86             return 1;
87             }
88            
89            
90            
91             1;
92             __END__