line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::UK::Postcode::Regex::Simple; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.015'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
76202
|
use strict; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
64
|
|
6
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
14
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
10
|
use base 'Exporter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
129
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
409
|
use Geo::UK::Postcode::Regex qw/ %REGEXES /; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1662
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ postcode_re extract_pc parse_pc validate_pc /; |
15
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $MODE = 'strict'; # or 'valid' or 'lax' |
18
|
|
|
|
|
|
|
our $PARTIAL = 0; |
19
|
|
|
|
|
|
|
our $ANCHORED = 1; |
20
|
|
|
|
|
|
|
our $CAPTURES = 1; |
21
|
|
|
|
|
|
|
our $CASE_INSENSITIVE = 0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub import { |
24
|
50
|
|
|
50
|
|
399090
|
my $class = shift; |
25
|
|
|
|
|
|
|
|
26
|
50
|
|
|
|
|
193
|
my %tags = map { $_ => 1 } @_; |
|
241
|
|
|
|
|
677
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$MODE |
29
|
|
|
|
|
|
|
= delete $tags{'-valid'} ? 'valid' |
30
|
|
|
|
|
|
|
: delete $tags{'-lax'} ? 'lax' |
31
|
50
|
100
|
|
|
|
360
|
: delete $tags{'-strict'} ? 'strict' |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
32
|
|
|
|
|
|
|
: $MODE; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$PARTIAL # |
35
|
|
|
|
|
|
|
= delete $tags{'-partial'} ? 1 |
36
|
50
|
100
|
|
|
|
229
|
: delete $tags{'-full'} ? 0 |
|
|
100
|
|
|
|
|
|
37
|
|
|
|
|
|
|
: $PARTIAL; |
38
|
|
|
|
|
|
|
$ANCHORED |
39
|
|
|
|
|
|
|
= delete $tags{'-unanchored'} ? 0 |
40
|
50
|
100
|
|
|
|
196
|
: delete $tags{'-anchored'} ? 1 |
|
|
100
|
|
|
|
|
|
41
|
|
|
|
|
|
|
: $ANCHORED; |
42
|
|
|
|
|
|
|
$CAPTURES |
43
|
|
|
|
|
|
|
= delete $tags{'-nocaptures'} ? 0 |
44
|
50
|
100
|
|
|
|
209
|
: delete $tags{'-captures'} ? 1 |
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
: $CAPTURES; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$CASE_INSENSITIVE |
48
|
|
|
|
|
|
|
= delete $tags{'-case-insensitive'} ? 1 |
49
|
50
|
100
|
|
|
|
195
|
: delete $tags{'-case-sensitive'} ? 0 |
|
|
100
|
|
|
|
|
|
50
|
|
|
|
|
|
|
: $CASE_INSENSITIVE; |
51
|
|
|
|
|
|
|
|
52
|
50
|
|
|
|
|
124
|
local $Exporter::ExportLevel = 1; |
53
|
50
|
|
|
|
|
1622
|
$class->SUPER::import( grep { /^[^\-]/ } keys %tags ); |
|
1
|
|
|
|
|
2992
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub postcode_re { |
57
|
|
|
|
|
|
|
|
58
|
49
|
100
|
|
49
|
1
|
759
|
croak "invalid \$MODE $MODE" if $MODE !~ m/^(?:strict|lax|valid)$/; |
59
|
|
|
|
|
|
|
|
60
|
48
|
|
|
|
|
125
|
my $key = $MODE; |
61
|
48
|
100
|
|
|
|
170
|
$key .= '_partial' if $PARTIAL; |
62
|
48
|
100
|
|
|
|
172
|
$key .= '_anchored' if $ANCHORED; |
63
|
48
|
100
|
|
|
|
153
|
$key .= '_captures' if $CAPTURES; |
64
|
48
|
100
|
|
|
|
159
|
$key .= '_case-insensitive' if $CASE_INSENSITIVE; |
65
|
|
|
|
|
|
|
|
66
|
48
|
|
|
|
|
345
|
return $REGEXES{$key}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub parse_pc { |
70
|
|
|
|
|
|
|
|
71
|
3600
|
50
|
|
3600
|
1
|
11293
|
croak "parse_pc only works with an anchored regex" unless $ANCHORED; |
72
|
|
|
|
|
|
|
|
73
|
3600
|
100
|
|
|
|
37591
|
Geo::UK::Postcode::Regex->parse( |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
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
|
50
|
|
3600
|
1
|
5250139
|
croak "extract_pc only works with full postcodes" if $PARTIAL; |
86
|
|
|
|
|
|
|
|
87
|
3600
|
100
|
|
|
|
27958
|
Geo::UK::Postcode::Regex->extract( |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
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
|
|
|
7177
|
1
|
11864281
|
my $pc = shift; |
98
|
|
|
|
|
|
|
|
99
|
7177
|
100
|
|
|
|
44064
|
croak "invalid \$MODE $MODE" if $MODE !~ m/^(?:strict|lax|valid)$/; |
100
|
|
|
|
|
|
|
|
101
|
7176
|
|
|
|
|
16302
|
my $key = $MODE; |
102
|
|
|
|
|
|
|
|
103
|
7176
|
100
|
|
|
|
19323
|
$key .= '_partial' if $PARTIAL; |
104
|
|
|
|
|
|
|
|
105
|
7176
|
100
|
|
|
|
18027
|
$key .= '_anchored' if $ANCHORED; |
106
|
|
|
|
|
|
|
|
107
|
7176
|
100
|
|
|
|
19649
|
$key .= '_case-insensitive' if $CASE_INSENSITIVE; |
108
|
|
|
|
|
|
|
|
109
|
7176
|
100
|
|
|
|
43578
|
return $pc =~ $REGEXES{$key} ? 1 : 0; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |