package Image::Maps::Plot::FromPostcode; # where in the world are members?

our $VERSION = 2;
our $DATE = "Tue 12 Feb  2003 15:33 CET";#"Mon 28 May 09:59 2002 CET"; #"Fri 06 July 19:18 2001 BST";
use 5.006;
use strict;
use warnings;

use base "Image::Maps::Plot::FromLatLong";

our %locations;
our $ADDENTRY;	# Should be object field

=head1 NAME

Image::Maps::Plot::FromPostcode - from postcodes plot world/regional maps in JPEG/HTML


This module is a sub-class of C<Image::Maps::Plot::FromLatLong>,
that uses the C<WWW::MapBlast> module to convert postcodes to
latitude and longitude.


=head2 METHOD add_entry

A method that accepts: $name, $country, $postcode

Looks up on the supplied details, and adds them to the db.

If an entry already exists for $name, will return C<undef> unless
the global scalar C<$ADDENTRY> is set to it's default value of C<MULTIPLE>,
in which case $name will be appended with $country and $postcode.

Does not save them to file - you must do that manually (L<"METHOD save_db">), but
note that you may wish to load the db before adding to it and saving.

Incidentaly returns a reference to the new key.

See also L<ADDING MAPS>.


sub add_entry { my ($self, $name,$country,$postcode) = (@_);
	eval('use WWW::MapBlast 0.02;');
	die "Can't add_entry without \$name, \$country, \$postcode "
		unless (defined $name and defined $country and defined $postcode);

	my ($lat,$lon,$address) = WWW::MapBlast::latlon($country,$postcode);
	$lat = 11111111 if not defined $lat or $lat eq '';
	$lon = 11111111 if not defined $lon or $lon eq '';
	if (not defined $address or $address eq ''){
		$address = "$postcode $country - didn't know"

	if (exists $locations{$name} ){
			warn "Not adding duplicate entry for $name at $postcode, $country.\n" if $self->{chat};
			return undef;
		$name .= " ($postcode $country)";

	$locations{$name} = {

	return \$locations{$name};

=head2 &remove_entry

A subroutine, not a method, that accepts the name field of the entry in the db, and returns
C<1> on success, C<undef> if no such entry exists.


sub remove_entry { my ($name) = (shift);
	return undef if not exists $locations{$name};
	delete $locations{$name};
	return 1;



I was bored and got this message on a list:

	[]On Behalf Of Philip Newton
	Sent: 21 June 2001 11:44
	To: ''
	Subject: Re: headers

	Simon Wistow wrote:
	> It's more a collection of people who have the common connection
	> that they live and london and like perl.
	> In fact neither of those actually have to be true since I personally
	> know two people on the list who don't program Perl and one of whom
	> doesn't even live in London.

	How many off-London people have we got? (Well, also excluding people who
	live near London.)

	From outside the UK, there's Damian, dha, Paul M, I; Lucy and lathos
	probably also qualify as far as I can tell. Marcel used to work in London
	(don't know whether he still does). Anyone else?

	Philip Newton <>
	All opinions are my own, not my employer's.
	If you're not part of the solution, you're part of the precipitate.

In the twenty-second weekly summary of the London Perl Mongers
mailing list, for the week starting 2001-06-18:

	In other news: ... a world map ...

Hence the module. At that time there were no maps to
plot from postcodes.


=over 4

=item 2

Made this a sub-class of the new C<*::FromLatLong> to
remove what has, for me personally, become redundent functionality.
Interface remains unchanged, I<I think>.

=item 1.2

Corrected a slight mis-positioning of points.

Replaced GD with Image::Magick as I was seeing terrible JPEG output
with GD.

Replaced support for non-maintained C<Image::GD::Thumbnail> with

Added methods to create just images and to return references to image blobs.

=item 1.0

Don't remember.

=item 0.25

Clean IMG path and double-header bugs

=item 0.23

Added more documentation; escaping of href text

=item 0.22

Added thumbnail images to index page


=head1 SEE ALSO

L<Image::Magick|> (C<>); L<File::Basename>; L<Acme::Pony>; L<Data::Dumper>; L<WWW::MapBlast>; L<Image::Thumbnail>

=head1 THANKS

Thanks to the group for their test data and insipration, to Leon for his patience with all that mess on the list, to Philip Newton for his frankly amazing knowledge of international postcodes.

Thanks also to the CIA, L<|>, L<The University of Texas|>,
and L<The Ordnance Survey|>
for their public-domain maps.

=head1 AUTHOR

Lee Goddard <>


Copyright (C) Lee Goddard, 2001.  All Rights Reserved.

This module is supplied and may be used under the same terms as Perl itself.

The public domain maps provided with this distribution are the property of their respective copyright holders.