blib/lib/Geo/UK/Postcode/Regex/Simple.pm

filter: Statementstmt 100% 53 / 53 Branchbran 96.6% 58 / 60 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 98.4% 125 / 127 SCAR 34.3
CC
31
Cov
98%
import
12.0
parse_pc
6.0
postcode_re
6.0
CRAP 31.0
« 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
BranchTrueFalseTotal
delete $tags{'-valid'} ? : 16 34 50
delete $tags{'-lax'} ? : 16 18 34
delete $tags{'-strict'} ? : 16 2 18
32 : $MODE;
33  
34 $PARTIAL #
35 = delete $tags{'-partial'} ? 1
36 50 ▶ : delete $tags{'-full'} ? 0
Branch: 2 branches
BranchTrueFalseTotal
delete $tags{'-partial'} ? : 24 26 50
delete $tags{'-full'} ? : 24 2 26
37 : $PARTIAL;
38 $ANCHORED
39 = delete $tags{'-unanchored'} ? 0
40 50 ▶ : delete $tags{'-anchored'} ? 1
Branch: 2 branches
BranchTrueFalseTotal
delete $tags{'-unanchored'} ? : 24 26 50
delete $tags{'-anchored'} ? : 24 2 26
41 : $ANCHORED;
42 $CAPTURES
43 = delete $tags{'-nocaptures'} ? 0
44 50 ▶ : delete $tags{'-captures'} ? 1
Branch: 2 branches
BranchTrueFalseTotal
delete $tags{'-nocaptures'} ? : 24 26 50
delete $tags{'-captures'} ? : 24 2 26
45 : $CAPTURES;
46  
47 $CASE_INSENSITIVE
48 = delete $tags{'-case-insensitive'} ? 1
49 50 ▶ : delete $tags{'-case-sensitive'} ? 0
Branch: 2 branches
BranchTrueFalseTotal
delete $tags{'-case-insensitive'} ? : 24 26 50
delete $tags{'-case-sensitive'} ? : 24 2 26
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
BranchTrueFalseTotal
unless $Geo::UK::Postcode::Regex::Simple::MODE =~ /^(?:strict|lax|valid)$/ 1 48 49
59  
60 48 my $key = $MODE;
61 48 ▶ $key .= '_partial' if $PARTIAL;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::PARTIAL 24 24 48
62 48 ▶ $key .= '_anchored' if $ANCHORED;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::ANCHORED 24 24 48
63 48 ▶ $key .= '_captures' if $CAPTURES;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::CAPTURES 24 24 48
64 48 ▶ $key .= '_case-insensitive' if $CASE_INSENSITIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::CASE_INSENSITIVE 24 24 48
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
BranchTrueFalseTotal
unless $Geo::UK::Postcode::Regex::Simple::ANCHORED 0 3600 3600
72  
73 3600 ▶ Geo::UK::Postcode::Regex->parse(
Branch: 4 branches
BranchTrueFalseTotal
$Geo::UK::Postcode::Regex::Simple::PARTIAL ? : 1800 1800 3600
$Geo::UK::Postcode::Regex::Simple::MODE eq 'lax' ? : 1200 2400 3600
$Geo::UK::Postcode::Regex::Simple::MODE eq 'valid' ? : 1200 2400 3600
$Geo::UK::Postcode::Regex::Simple::CASE_INSENSITIVE ? : 1800 1800 3600
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
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::PARTIAL 0 3600 3600
86  
87 3600 ▶ Geo::UK::Postcode::Regex->extract(
Branch: 3 branches
BranchTrueFalseTotal
$Geo::UK::Postcode::Regex::Simple::MODE eq 'lax' ? : 1200 2400 3600
$Geo::UK::Postcode::Regex::Simple::MODE eq 'valid' ? : 1200 2400 3600
$Geo::UK::Postcode::Regex::Simple::CASE_INSENSITIVE ? : 1800 1800 3600
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
BranchTrueFalseTotal
unless $Geo::UK::Postcode::Regex::Simple::MODE =~ /^(?:strict|lax|valid)$/ 1 7176 7177
100  
101 7176 my $key = $MODE;
102  
103 7176 ▶ $key .= '_partial' if $PARTIAL;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::PARTIAL 3576 3600 7176
104  
105 7176 ▶ $key .= '_anchored' if $ANCHORED;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::ANCHORED 3600 3576 7176
106  
107 7176 ▶ $key .= '_case-insensitive' if $CASE_INSENSITIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::UK::Postcode::Regex::Simple::CASE_INSENSITIVE 3588 3588 7176
108  
109 7176 ▶ return $pc =~ $REGEXES{$key} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$pc =~ /$Geo::UK::Postcode::Regex::Simple::REGEXES{$key}/ ? : 3852 3324 7176
110 }
111  
112 2 1;
113  
114 __END__
« blib/lib/Geo/UK/Postcode/Regex.pm ↑ Summary blib/lib/auto/share/dist/Geo-UK-Postcode-Regex/get_pc_districts.pl »