
Geo::CountryFlags::Util - Makefile.PL and update utilities

require Geo::CountryFlags::Util; my $gcu = new Geo::CountryFlags::Util;

Methods and functions to facilitate the update and rebuild the various cross reference tables in these modules as the CIA and ISO committees update the country codes and country flags.
Recursive decent directory and file removal. USE WITH CAUTION This function removes all the files and directories BELOW its argument but does not remove the directory itself. If the function returns DEFINED, the argument directory may safely be removed with:
rmdir $dir;
input: directory/path
returns: number of files & dirs removed
or undef on error
If an error is returned, the delete may be partially complete.
NOTE: an error is considered to be a non-existent directory or a file that is not a real file or directory. i.e. a link, pipe, etc...
Return an updated version number. Called from within this module
input: [optional] old version number returns: new or updated version number
Return a method pointer to the Geo::CountryFlags::Util package.
input: none returns: method pointer
Compare files and return true if the second file is missing or the modification time of the second file is older than the modification time of the first file.
input: path/to/firstfile,
path/to/secondfile
return: true/false
returns false if
first file is missing
Check that file exists and that its modification time is not less than timestamp.
input: path/to/file,
timestamp seconds since epoch
returns: false, file missing
true, file && timestamp missing
true if current
else false
Remake a module for this distribution. A module of name:
Geo::CountryFlags::${mtitle}.pm
is made or updated in the lib/Geo/CountryFlags directory.
input: hash pointer to contents
module title (short version),
creates: new module in lib/Geo/CountryFlags
returns: path to module
|. $package .q| is autogenerated by Makefile.PL
Last updated |. (scalar gmtime()) .q| GMT

|. $package .'::'. $mt .q| - hash to map values

|. $package .q| provides a variety of methods and functions to lookup values either as hash-like constants (recommended) or directly from a hash array.
require $|. $package .q|;
my $|. $gcv .q| = new |. $package .q|;
$value = $|. $gcv .q|->KEY;
Perl 5.6 or greater can use syntax
$value = $|. $gcv .q|->$key;
or
$subref = subref |. $package .q|;
$value = $subref->($key);
$value = &$subref($key);
or
$value = value |. $package .q|($key);
|. $package .q|->value($key);
to return a reference to the map directly
$hashref = hashptr |. $package .q|($class);
$value = $hashref->{$key};

|. $package .q| maps |. $mt .q| values.
Values may be returned directly by designating the KEY as a method or subroutine of the form:
$value = |. $package .q|::KEY;
$value = |. $package .q|->KEY;
or in Perl 5.6 and above
$value = |. $package .q|->$key;
or
$|. $gcv .q| = new |. $package .q|;
$value = $|. $gcv .q|->KEY;
or in Perl 5.6 and above
$value= = $|. $gcv .q|->$key;
Return a reference to the modules in this package.
Return a blessed reference to a copy of the hash in this package.
input: [optional] class or class ref
returns: a reference blessed into $class
if $class is present otherwise
blessed into |. $package .q|
Return the value in the map hash or undef if it does not exist.
Return a subroutine reference that will return the value of a key or undef if the key is not present.
$value = $subref->($key); $value = &$subref($key);

Nothing

Michael Robinton michael@bizsystems.com

Copyright 2006 Michael Robinton, michael@bizsystems.com
This module is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version,
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Return the last modified time for the web page designated by $name.
input: CIA or ISO
returns: seconds since the epoch
or false on error
Fetch the Map_Exceptions file and extract the contents, returning a hash pointer of the form:
ISO compressed name CIA short name i.e. 'korea republic' => 'korea south',
The ISO compressed name is 'exactly' as produced by Makefile.PL when rebuilding the ISO/CIA flag cross reference. The CIA short names are at least enough of the compressed name produced by Makefile.PL to uniquely identify the entry.
input: [optional] path to file
returns: blessed reference
or undef on failure
Fetch the Valid_Urls file and extract the contents, returning a hash pointer of the form:
keys vals
CIA CIA factbook flags page URL
CIAFLAGS CIA flags file directory URL
ISO ISO country code file URL
input: [optional] path to file
returns: blessed reference
or undef on failure
Fetch the page text from the CIA web site, parse it and return a hash pointer of the form:
keys vals
country_code country_name
input: [optional] cia page url
returns: blessed reference
or undef on failure
Fetch the page text from the ISO web site, parse it and return a hash pointer of the form:
keys vals
country_code country_name
input: [optional] iso page url
returns: blessed reference
or undef on failure

These methods/functions are used to create the ISO => CIA flag map and are mostly used within this module.
Map the known exceptions into the reverse ISO hash
input: ref to reverse ISO hash,
ref to exceptions hash
returns: nothing
Replaces the original keys with the exception keys
Return a new blessed reference to hash with the keys and values reversed and compressed where the values are all lowercased and all non-alphanumeric characters and extra spaces are removed. The fill words of the and de da are deleted from the key string.
i.e. vals => keys
input: ref to blessed hash
returns: blessed reference to
compressed/reversed hash
Return or update a cross reference hash of the form:
val rgci => val rgcc
where the keys in rgci and rgcc match exactly
input: ISO reverse hash,
CIA reverse hash,
[optional] cross ref hash
returns: blessed reference to
cross reference hash
Parse the key values in @candidates for matches in $rgcc keys to the regular expression supplied in $regexp. If only one match is found, update the $cross->{hash} and delete the entry in $rgci pointed to by $ikey and the match entry in $rgcc, then return true. If no match is found or more than one match is found, return false.
input: ptr to reverse gci hash
ptr to reverse gcc hash
ptr to cross reference hash
ptr to candidates array
reverse gci key
regular expression
returns: true if unique match found
else returns false
Look for near matches of $rgci keys to $rgcc keys by doing a string match a word at a time using the key values in $rgci checked against all keys in $rgcc.
i.e. @words = split(/\s/,$rgcikey)
first $rgcckey =~ /word[0]/;
then $rgcckey =~ /word[0] word[1]/
and so on...
input: ptr to reverse gci hash
ptr to reverse gcc hash
ptr to cross reference
returns: nothing