Michael Jemmeson
and 1 contributors

NAME

Geo::UK::Postcode::Regex::Simple - Simplified interface to Geo::UK::Postcode::Regex

SYNOPSIS

Localised configuration:

    use Geo::UK::Postcode::Regex::Simple ':all';

    # Set behaviour of regular expression (defaults below)
    local $Geo::UK::Postcode::Regex::Simple::MODE             = 'strict';
    local $Geo::UK::Postcode::Regex::Simple::PARTIAL          = 0;
    local $Geo::UK::Postcode::Regex::Simple::CAPTURES         = 1;
    local $Geo::UK::Postcode::Regex::Simple::ANCHORED         = 1;
    local $Geo::UK::Postcode::Regex::Simple::CASE_INSENSITIVE = 0;

    # Regular expression to match postcodes
    my $re = postcode_re;
    my ( $area, $district, $sector, $unit ) = "AB10 1AA" =~ $re;

    # Get hashref of data parsed from postcode
    my $parsed = parse_pc "AB10 1AA";

    # Extract list of postcodes from text string
    my @extracted = extract_pc $text;

    # Check if string is a correct postcode
    if ( validate_pc $string ) {
        ...
    }

Alternate global configuration:

    use Geo::UK::Postcode::Regex::Simple    #
        ':all'                              #
        -strict                             # or -lax, -valid
        -full                               # or -partial
        -anchored                           # or -unanchored
        -captures                           # or -nocaptures
        -case-sensitive                     # or -case-insensitive
        ;

DESCRIPTION

Alternative interface to Geo::UK::Postcode::Regex.

IMPORTANT CHANGES FOR VERSION 0.014

Please note that various bugfixes have changed the following:

  • extract_pc, parse_pc now die with invalid import options set

  • Unanchored regular expressions no longer match valid postcodes within invalid ones.

  • Unanchored regular expressions in partial mode now can match a valid or strict outcode with an invalid incode.

Please get in touch if you have any questions.

CONFIGURATION

MODE

Sets the regular expressions used to be in one of the following modes:

lax

Matches anything that resembles a postcode.

strict (default)

Matches only if postcode contains valid characters in the correct positions.

valid

Matches only if the postcode contains valid characters and the outcode exists.

PARTIAL (default = false )

If true, regular expression returned by postcode_re will match partial postcodes, at district (outcode) or sector level, e.g. "AB10" or "AB10 1".

ANCHORED (default = true )

Puts anchors (^ and $) around the regular expression returned by postcode_re.

CAPTURES (default = true )

Puts capture groups into the regular expression returned by postcode_re. The matches returned upon a successful match are: area, district, sector and unit (or outcode, sector and unit for 'valid' mode).

CASE_INSENSITIVE (default = false)

If false, only parses/matches/extracts postcodes that contain only upper case characters.

FUNCTIONS

postcode_re

    my $re = postcode_re;

Returns a regular expression which will match UK Postcodes. See CONFIGURATION for details.

parse_pc

    my $parsed = parse_pc $pc;

Returns a hashref of data extracted from the postcode. See parse in Geo::UK::Postcode::Regex for more details.

extract_pc

    my @extracted = extract_pc $test;

Returns a list of postcodes extracted from a text string. See extract in Geo::UK::Postcode::Regex for more details.

validate_pc

    if ( validate_pc $pc ) {
        ...
    }

Boolean test for if a string is a (full) postcode or not, according to current MODE (see CONFIGURATION).

AUTHOR

Michael Jemmeson <mjemmeson@cpan.org>

COPYRIGHT

Copyright 2015- Michael Jemmeson

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.