« blib/lib/Geo/UK/Postcode/Regex.pm
↑ Summary
blib/lib/auto/share/dist/Geo-UK-Postcode-Regex/get_pc_districts.pl »
| 1 | package Geo::UK::Postcode::Regex::Simple; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.015'; | |||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 2 | ▶ | use base 'Exporter'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 2 | ▶ | use Geo::UK::Postcode::Regex qw/ %REGEXES /; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 2 | our @EXPORT_OK = qw/ postcode_re extract_pc parse_pc validate_pc /; | |||||||||||||||||||||
| 15 | 2 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 2 | our $MODE = 'strict'; # or 'valid' or 'lax' | |||||||||||||||||||||
| 18 | 2 | our $PARTIAL = 0; | |||||||||||||||||||||
| 19 | 2 | our $ANCHORED = 1; | |||||||||||||||||||||
| 20 | 2 | our $CAPTURES = 1; | |||||||||||||||||||||
| 21 | 2 | our $CASE_INSENSITIVE = 0; | |||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | sub import { | ||||||||||||||||||||||
| 24 | 50 | ▶ | my $class = shift; | ||||||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=24.8
| |||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | 50 | my %tags = map { $_ => 1 } @_; | |||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | $MODE | ||||||||||||||||||||||
| 29 | = delete $tags{'-valid'} ? 'valid' | ||||||||||||||||||||||
| 30 | : delete $tags{'-lax'} ? 'lax' | ||||||||||||||||||||||
| 31 | 50 | ▶ | : delete $tags{'-strict'} ? 'strict' | ||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||
| 32 | : $MODE; | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | $PARTIAL # | ||||||||||||||||||||||
| 35 | = delete $tags{'-partial'} ? 1 | ||||||||||||||||||||||
| 36 | 50 | ▶ | : delete $tags{'-full'} ? 0 | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 37 | : $PARTIAL; | ||||||||||||||||||||||
| 38 | $ANCHORED | ||||||||||||||||||||||
| 39 | = delete $tags{'-unanchored'} ? 0 | ||||||||||||||||||||||
| 40 | 50 | ▶ | : delete $tags{'-anchored'} ? 1 | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 41 | : $ANCHORED; | ||||||||||||||||||||||
| 42 | $CAPTURES | ||||||||||||||||||||||
| 43 | = delete $tags{'-nocaptures'} ? 0 | ||||||||||||||||||||||
| 44 | 50 | ▶ | : delete $tags{'-captures'} ? 1 | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 45 | : $CAPTURES; | ||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | $CASE_INSENSITIVE | ||||||||||||||||||||||
| 48 | = delete $tags{'-case-insensitive'} ? 1 | ||||||||||||||||||||||
| 49 | 50 | ▶ | : delete $tags{'-case-sensitive'} ? 0 | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 50 | : $CASE_INSENSITIVE; | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 50 | local $Exporter::ExportLevel = 1; | |||||||||||||||||||||
| 53 | 50 | $class->SUPER::import( grep { /^[^\-]/ } keys %tags ); | |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | sub postcode_re { | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | 49 | ▶ | croak "invalid \$MODE $MODE" if $MODE !~ m/^(?:strict|lax|valid)$/; | ||||||||||||||||||||
|
Subroutine
postcode_re: called CC=6 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | 48 | my $key = $MODE; | |||||||||||||||||||||
| 61 | 48 | ▶ | $key .= '_partial' if $PARTIAL; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | 48 | ▶ | $key .= '_anchored' if $ANCHORED; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 63 | 48 | ▶ | $key .= '_captures' if $CAPTURES; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 64 | 48 | ▶ | $key .= '_case-insensitive' if $CASE_INSENSITIVE; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | 48 | return $REGEXES{$key}; | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | sub parse_pc { | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | 3600 | ▶ | croak "parse_pc only works with an anchored regex" unless $ANCHORED; | ||||||||||||||||||||
|
Subroutine
parse_pc: called CC=6 SCAR=18.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 3600 | ▶ | Geo::UK::Postcode::Regex->parse( | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 74 | shift, | ||||||||||||||||||||||
| 75 | { partial => $PARTIAL ? 1 : 0, | ||||||||||||||||||||||
| 76 | strict => $MODE eq 'lax' ? 0 : 1, | ||||||||||||||||||||||
| 77 | valid => $MODE eq 'valid' ? 1 : 0, | ||||||||||||||||||||||
| 78 | 'case-insensitive' => $CASE_INSENSITIVE ? 1 : 0, | ||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | sub extract_pc { | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 3600 | ▶ | croak "extract_pc only works with full postcodes" if $PARTIAL; | ||||||||||||||||||||
|
Subroutine
extract_pc: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | 3600 | ▶ | Geo::UK::Postcode::Regex->extract( | ||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||
| 88 | shift, | ||||||||||||||||||||||
| 89 | { strict => $MODE eq 'lax' ? 0 : 1, | ||||||||||||||||||||||
| 90 | valid => $MODE eq 'valid' ? 1 : 0, | ||||||||||||||||||||||
| 91 | 'case-insensitive' => $CASE_INSENSITIVE ? 1 : 0, | ||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | sub validate_pc { | ||||||||||||||||||||||
| 97 | 7177 | ▶ | my $pc = shift; | ||||||||||||||||||||
|
Subroutine
validate_pc: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | 7177 | ▶ | croak "invalid \$MODE $MODE" if $MODE !~ m/^(?:strict|lax|valid)$/; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | 7176 | my $key = $MODE; | |||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 7176 | ▶ | $key .= '_partial' if $PARTIAL; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | 7176 | ▶ | $key .= '_anchored' if $ANCHORED; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | 7176 | ▶ | $key .= '_case-insensitive' if $CASE_INSENSITIVE; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | 7176 | ▶ | return $pc =~ $REGEXES{$key} ? 1 : 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | 2 | 1; | |||||||||||||||||||||
| 113 | |||||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||||