NAME

Geo::Coder::Free::Validate - The rule that decides whether a string could be a location

VERSION

Version 0.47

DESCRIPTION

One question, asked in three places: could this string be a location at all? Geo::Coder::Free::geocode() asks it of a location and of a scantext before it queries a backend, and Geo::Coder::Free::MaxMind and Geo::Coder::Free::OpenAddresses ask it of what a caller hands them directly. The rule lives here rather than being written out at each of those places, so they cannot drift apart on which strings are worth looking up - a string the facade refuses must not be accepted by a backend, and the other way round.

It is a cheap syntactic test and nothing more. A true answer means the string is not disqualified, not that a backend knows it: 'Ramsgate, Kent' is a location and may still find nothing. What is disqualified is a string of digits only, which is what a numeric column holds when the wrong column has been read, plus undef, the empty string and a reference. Anything with a non-digit character in it counts, '3.14' and '-' included - including a comma, which is why a rejected '0044' is a column mistake rather than a missing place.

A caller should not need this module: the same rule is public as $geo->valid_location($row->{'place'}), which is what a batch caller should pre-filter with. The sub is exported under its private name because the facade and the backends are the only intended callers, and because its public spelling already exists and has a name a caller can rely on.

SUBROUTINES/METHODS

_valid_location

Whether the string handed to it could be a location. False for undef, for '', for a reference and for a string of digits only; true for anything else, including a single punctuation character.

use Geo::Coder::Free::Validate qw(_valid_location);

if(_valid_location($row->{'place'})) {
    # worth a lookup
}

AUTHOR

Nigel Horne, <njh at nigelhorne.com>

LICENSE AND COPYRIGHT

Copyright 2017-2026 Nigel Horne.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.