blib/lib/Geo/Postcodes/NO.pm

filter: Statementstmt 88.6% 320 / 361 Branchbran 72.6% 218 / 300 Conditioncond 50.0% 82 / 164 MC/DCmcdc 28.4% 27 / 95 Subroutinesub 96.6% 58 / 60 Podpod 100% 38 / 38 totaltotal 72.9% 743 / 1018 CC 419 SCAR 37.8
CC
419
Cov
75%
_verify_selectionlist
215.5
_verify_selectionlist
215.5
_apply_next_clause
57.5
CRAP 43.7
« blib/lib/Geo/Postcodes/NO/Check.pm ↑ Summary eg/selection.pl »
1 package Geo::Postcodes::NO;
2  
3 17 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Geo::Postcodes::NO::Check ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 our $VERSION = '1.00';
12  
13 17 our $SOURCE_URL = 'https://www.bring.no/postnummerregister-ansi.txt';
14 17 our $DATA_VALID_FROM = '2026-10-01';
15 17 our $DATA_FILE = 'postnummerregister-ansi.txt';
16 17 our $DATA_ENV = 'GEO_POSTCODES_NO_DATA';
17 17 our $DATA_ENCODING = 'cp1252';
18 17 our $DATA_ENCODING_ENV = 'GEO_POSTCODES_NO_ENCODING';
19  
20 17 my @VALID_FIELDS = qw(postcode location borough borough_number county type type_verbose);
21 17 my %VALID_FIELD = map { $_ => 1 } @VALID_FIELDS;
22  
23 17 my %COUNTY = %{ Geo::Postcodes::NO::Check::county_table() };
24  
25 17 my %BRING_CATEGORY_TO_TYPE = (
26 G => 'ST',
27 P => 'BX',
28 B => 'STBX',
29 S => 'SX',
30 );
31  
32 17 my %TYPE_DESC = (
33 BX => 'Postboks',
34 ST => 'Gateadresse',
35 SX => 'Serviceboks',
36 IO => 'Kunde med eget postnummer',
37 STBX => 'Både gateadresse og postboks',
38 MU => 'Flere bruksområder (felles)',
39 PP => 'Porto betalt av mottaker',
40 PN => 'Stedsnavn',
41 );
42  
43 17 my %TYPE_DESC_EN = (
44 BX => 'Post Office box',
45 ST => 'Street address',
46 SX => 'Service box',
47 IO => 'Individual owner',
48 STBX => 'Street Address and Post Office box',
49 MU => 'Multiple usage',
50 PP => 'Porto Paye receiver',
51 PN => 'Place name',
52 );
53  
54 17 my %LEGAL_MODE = map { $_ => 1 } (
55 'and', 'and not',
56 'nand', 'nand not',
57 'oldnand', 'oldnand not',
58 'nor', 'nor not',
59 'or', 'or not',
60 'xnor', 'xnor not',
61 'xor', 'xor not',
62 );
63  
64 17 my %LEGAL_INITIAL_MODE = (
65 %LEGAL_MODE,
66 all => 1,
67 none => 1,
68 not => 1,
69 one => 1,
70 );
71  
72 17 my (%LOCATION, %BOROUGH_NUMBER, %BOROUGH, %TYPE, %BRING_CATEGORY);
73 17 my ($LOADED_DATA_FILE, $LOADED_DATA_ENCODING, $LOADED_FROM_ENV);
74  
75 17 _load_data();
76  
77 1089 ▶sub new {
Subroutine new: called CC=2 SCAR=9.2
Pod documented
78 0 ▶ my ($class, $postcode) = @_;
Subroutine new: not called CC=2 SCAR=9.2
Pod documented
79  
80 0 ▶ return unless valid($postcode);
Branch: 2 branches
BranchTrueFalseTotal
unless valid($postcode) 3 1086 1089
unless valid($postcode) 0 0 0
81  
82 0 return bless {
83 postcode => $postcode,
84 location => location_of($postcode),
85 borough_number => borough_number_of($postcode),
86 borough => borough_of($postcode),
87 county => county_of($postcode),
88 type => type_of($postcode),
89 }, $class;
90 }
91  
92 1086 ▶sub postcode { return _object_field($_[0], 'postcode') }
Subroutine postcode: called CC=1 SCAR=0.0
Pod documented
93 1084 ▶sub location { return _object_field($_[0], 'location') }
Subroutine location: called CC=1 SCAR=0.0
Pod documented
94 1084 ▶sub borough_number { return _object_field($_[0], 'borough_number') }
Subroutine borough_number: called CC=1 SCAR=0.0
Pod documented
95 1084 ▶sub borough { return _object_field($_[0], 'borough') }
Subroutine borough: called CC=1 SCAR=0.0
Pod documented
96 1084 ▶sub county { return _object_field($_[0], 'county') }
Subroutine county: called CC=1 SCAR=0.0
Pod documented
97 1086 ▶sub type { return _object_field($_[0], 'type') }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
98  
99 1084 ▶sub type_verbose {
Subroutine type_verbose: called CC=2 SCAR=7.1
Pod documented
100 1084 my $self = shift;
101 1084 ▶ return unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1084 1084
102 1084 return type2verbose($self->{type});
103 }
104  
105 7 ▶sub get_fields {
Subroutine get_fields: called CC=1 SCAR=0.0
Pod documented
106 7 return @VALID_FIELDS;
107 }
108  
109 79 ▶sub is_field {
Subroutine is_field: called CC=5 SCAR=16.3
Pod documented
110 79 ▶ shift if @_ > 1 && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and _looks_like_invocant($_[0]) 8 71 79
Condition66%2/3
@_ > 1 and _looks_like_invocant($_[0])
!ll&&!rl&&r
7108
MC/DC50%1/2
@_ > 1 and _looks_like_invocant($_[0])
@_ > 1 _looks_like_invocant($_[0])
Truth table66%2/3
A and B
A= @_ > 1B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
111 79 my $field = shift;
112  
113 79 ▶ return 0 unless defined $field;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 79 79
114 79 ▶ return $VALID_FIELD{$field} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$VALID_FIELD{$field} ? : 72 7 79
115 }
116  
117 6214 ▶sub legal {
Subroutine legal: called CC=3 SCAR=11.1
Pod documented
118 6214 my $postcode = shift;
119 6214 ▶ return 0 unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 6214 6214
120 6214 ▶ return $postcode =~ /\A[0-9]{4}\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$postcode =~ /\A[0-9]{4}\z/ ? : 6210 4 6214
121 }
122  
123 6209 ▶sub valid {
Subroutine valid: called CC=3 SCAR=11.0
Pod documented
124 6209 my $postcode = shift;
125 6209 ▶ return 0 unless legal($postcode);
Branch: 1 branch
BranchTrueFalseTotal
unless legal($postcode) 1 6208 6209
126 6208 ▶ return exists $LOCATION{$postcode} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $LOCATION{$postcode} ? : 6203 5 6208
127 }
128  
129 123227 ▶sub postcode_of {
Subroutine postcode_of: called CC=1 SCAR=0.0
Pod documented
130 123227 my $postcode = shift;
131 123227 return $postcode;
132 }
133  
134 11359 ▶sub location_of {
Subroutine location_of: called CC=2 SCAR=7.1
Pod documented
135 11359 my $postcode = shift;
136 11359 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 11359 11359
137 11359 return $LOCATION{$postcode};
138 }
139  
140 28827 ▶sub borough_number_of {
Subroutine borough_number_of: called CC=2 SCAR=7.1
Pod documented
141 28827 my $postcode = shift;
142 28827 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 28827 28827
143 28827 return $BOROUGH_NUMBER{$postcode};
144 }
145  
146 6201 ▶sub borough_number2borough {
Subroutine borough_number2borough: called CC=2 SCAR=7.1
Pod documented
147 6201 my $borough_number = shift;
148 6201 ▶ return unless defined $borough_number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $borough_number 0 6201 6201
149 6201 return $BOROUGH{$borough_number};
150 }
151  
152 6201 ▶sub borough_of {
Subroutine borough_of: called CC=3 SCAR=11.3
Pod documented
153 6201 my $postcode = shift;
154 6201 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 6201 6201
155  
156 6201 my $borough_number = borough_number_of($postcode);
157 6201 ▶ return unless defined $borough_number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $borough_number 0 6201 6201
158 6201 return borough_number2borough($borough_number);
159 }
160  
161 21538 ▶sub county_of {
Subroutine county_of: called CC=3 SCAR=11.3
Pod documented
162 21538 my $postcode = shift;
163 21538 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 21538 21538
164  
165 21538 my $borough_number = borough_number_of($postcode);
166 21538 ▶ return unless defined $borough_number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $borough_number 0 21538 21538
167 21538 return borough_number2county($borough_number);
168 }
169  
170 21538 ▶sub borough_number2county {
Subroutine borough_number2county: called CC=4 SCAR=14.5
Pod documented
171 21538 my $borough_number = shift;
172 21538 ▶ return unless defined $borough_number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $borough_number 0 21538 21538
173 21538 ▶ return unless exists $BOROUGH{$borough_number};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $BOROUGH{$borough_number} 0 21538 21538
174  
175 21538 my ($county_number) = $borough_number =~ /\A([0-9]{2})/;
176 21538 ▶ return unless defined $county_number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $county_number 0 21538 21538
177 21538 return $COUNTY{$county_number};
178 }
179  
180 64414 ▶sub type_of {
Subroutine type_of: called CC=2 SCAR=7.1
Pod documented
181 64414 my $postcode = shift;
182 64414 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 64414 64414
183 64414 return $TYPE{$postcode};
184 }
185  
186 5114 ▶sub type_verbose_of {
Subroutine type_verbose_of: called CC=3 SCAR=11.3
Pod documented
187 5114 my $postcode = shift;
188 5114 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 5114 5114
189  
190 5114 my $type = type_of($postcode);
191 5114 ▶ return unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 5114 5114
192 5114 return type2verbose($type);
193 }
194  
195 6199 ▶sub type2verbose {
Subroutine type2verbose: called CC=4 SCAR=15.6
Pod documented
196 6199 ▶ shift if @_ > 1 && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and _looks_like_invocant($_[0]) 0 6199 6199
Condition33%1/3
@_ > 1 and _looks_like_invocant($_[0])
!ll&&!rl&&r
619900
MC/DC0%0/2
@_ > 1 and _looks_like_invocant($_[0])
@_ > 1 _looks_like_invocant($_[0])
Truth table33%1/3
A and B
A= @_ > 1B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
197 6199 my $type = shift;
198  
199 6199 ▶ return unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 6199 6199
200 6199 return $TYPE_DESC{$type};
201 }
202  
203 3 ▶sub type2verbose_english {
Subroutine type2verbose_english: called CC=4 SCAR=15.6
Pod documented
204 3 ▶ shift if @_ > 1 && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and _looks_like_invocant($_[0]) 0 3 3
Condition33%1/3
@_ > 1 and _looks_like_invocant($_[0])
!ll&&!rl&&r
300
MC/DC0%0/2
@_ > 1 and _looks_like_invocant($_[0])
@_ > 1 _looks_like_invocant($_[0])
Truth table33%1/3
A and B
A= @_ > 1B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
205 3 my $type = shift;
206  
207 3 ▶ return unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 3 3
208 3 return $TYPE_DESC_EN{$type};
209 }
210  
211 1 ▶sub get_types {
Subroutine get_types: called CC=1 SCAR=0.0
Pod documented
212 1 return sort keys %TYPE_DESC;
213 }
214  
215 41 ▶sub get_postcodes {
Subroutine get_postcodes: called CC=1 SCAR=0.0
Pod documented
216 41 return keys %LOCATION;
217 }
218  
219 1 ▶sub bring_category_of {
Subroutine bring_category_of: called CC=2 SCAR=7.1
Pod documented
220 1 my $postcode = shift;
221 1 ▶ return unless defined $postcode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $postcode 0 1 1
222 1 return $BRING_CATEGORY{$postcode};
223 }
224  
225 0 ▶sub source_url {
Subroutine source_url: not called CC=1 SCAR=6.9
Pod documented
226 0 return $SOURCE_URL;
227 }
228  
229 3 ▶sub data_valid_from {
Subroutine data_valid_from: called CC=2 SCAR=6.9
Pod documented
230 3 ▶ return if $LOADED_FROM_ENV;
Branch: 1 branch
BranchTrueFalseTotal
if $LOADED_FROM_ENV 2 1 3
231 1 return $DATA_VALID_FROM;
232 }
233  
234 7 ▶sub data_file {
Subroutine data_file: called CC=2 SCAR=7.6
Pod documented
235 7 ▶ return defined $LOADED_DATA_FILE ? $LOADED_DATA_FILE : _data_path();
Branch: 1 branch
BranchTrueFalseTotal
defined $LOADED_DATA_FILE ? : 7 0 7
236 }
237  
238 2 ▶sub data_encoding {
Subroutine data_encoding: called CC=4 SCAR=17.9
Pod documented
239 2 ▶ shift if @_ && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ and _looks_like_invocant($_[0]) 0 2 2
Condition33%1/3
@_ and _looks_like_invocant($_[0])
!ll&&!rl&&r
200
MC/DC0%0/2
@_ and _looks_like_invocant($_[0])
@_ _looks_like_invocant($_[0])
Truth table33%1/3
A and B
A= @_B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
240 2 ▶ return $LOADED_DATA_ENCODING if defined $LOADED_DATA_ENCODING;
Branch: 1 branch
BranchTrueFalseTotal
if defined $LOADED_DATA_ENCODING 2 0 2
241 0 return _data_encoding();
242 }
243  
244 27 ▶sub is_legal_selectionmode {
Subroutine is_legal_selectionmode: called CC=5 SCAR=17.5
Pod documented
245 27 ▶ shift if @_ > 1 && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and _looks_like_invocant($_[0]) 0 27 27
Condition33%1/3
@_ > 1 and _looks_like_invocant($_[0])
!ll&&!rl&&r
2700
MC/DC0%0/2
@_ > 1 and _looks_like_invocant($_[0])
@_ > 1 _looks_like_invocant($_[0])
Truth table33%1/3
A and B
A= @_ > 1B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
246 27 my $mode = shift;
247  
248 27 ▶ return 0 unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 27 27
249 27 ▶ return $LEGAL_MODE{$mode} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$LEGAL_MODE{$mode} ? : 22 5 27
250 }
251  
252 39 ▶sub is_legal_initial_selectionmode {
Subroutine is_legal_initial_selectionmode: called CC=5 SCAR=17.5
Pod documented
253 39 ▶ shift if @_ > 1 && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and _looks_like_invocant($_[0]) 0 39 39
Condition33%1/3
@_ > 1 and _looks_like_invocant($_[0])
!ll&&!rl&&r
3900
MC/DC0%0/2
@_ > 1 and _looks_like_invocant($_[0])
@_ > 1 _looks_like_invocant($_[0])
Truth table33%1/3
A and B
A= @_ > 1B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
254 39 my $mode = shift;
255  
256 39 ▶ return 0 unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 39 39
257 39 ▶ return $LEGAL_INITIAL_MODE{$mode} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$LEGAL_INITIAL_MODE{$mode} ? : 2 37 39
258 }
259  
260 1 ▶sub get_selectionmodes {
Subroutine get_selectionmodes: called CC=1 SCAR=0.0
Pod documented
261 1 return sort keys %LEGAL_MODE;
262 }
263  
264 1 ▶sub get_initial_selectionmodes {
Subroutine get_initial_selectionmodes: called CC=1 SCAR=0.0
Pod documented
265 1 return sort keys %LEGAL_INITIAL_MODE;
266 }
267  
268 5 ▶sub verify_selectionlist {
Subroutine verify_selectionlist: called CC=3 SCAR=11.7
Pod documented
269 5 ▶ shift if @_ && _looks_like_invocant($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @_ and _looks_like_invocant($_[0]) 0 5 5
Condition66%2/3
@_ and _looks_like_invocant($_[0])
!ll&&!rl&&r
140
MC/DC0%0/2
@_ and _looks_like_invocant($_[0])
@_ _looks_like_invocant($_[0])
Truth table66%2/3
A and B
A= @_B= _looks_like_invocant($_[0])
ABresult
0X0
100
111
270 5 return _verify_selectionlist(@_);
271 }
272  
273 3 ▶sub selection_loop {
Subroutine selection_loop: called CC=5 SCAR=17.0
Pod documented
274 3 my $objects_requested = _shift_class_invocant(\@_);
275 3 my $procedure = shift;
276  
277 3 ▶ return 0 unless $procedure && ref $procedure eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $procedure and ref $procedure eq "CODE" 0 3 3
Condition33%1/3
$procedure and ref $procedure eq "CODE"
!ll&&!rl&&r
003
MC/DC0%0/2
$procedure and ref $procedure eq "CODE"
$procedure ref $procedure eq "CODE"
Truth table33%1/3
A and B
A= $procedureB= ref $procedure eq "CODE"
ABresult
0X0
100
111
278  
279 3 my @postcodes = _selection($objects_requested, @_);
280 3 ▶ return 0 unless @postcodes;
Branch: 1 branch
BranchTrueFalseTotal
unless @postcodes 0 3 3
281  
282 3 for my $postcode (@postcodes) {
283 635 $procedure->($postcode);
284 }
285  
286 3 return 1;
287 }
288  
289 35 ▶sub selection {
Subroutine selection: called CC=1 SCAR=0.0
Pod documented
290 35 my $objects_requested = _shift_class_invocant(\@_);
291 35 return _selection($objects_requested, @_);
292 }
293  
294 5 ▶sub _verify_selectionlist {
Subroutine _verify_selectionlist: called CC=28 SCAR=53.7
295 5 my @args = @_;
296 5 my $status = 1;
297 5 my @out;
298 my @verbose;
299  
300 5 ▶ return (0, 'No arguments') unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 4 5
301  
302 4 ▶ if (is_legal_initial_selectionmode($args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_legal_initial_selectionmode($args[0])) 0 4 4
303 0 my $mode = shift @args;
304  
305 0 ▶ if (@args && defined $args[0] && $args[0] eq 'not'
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[0] and $args[0] eq "not" and is_legal_initial_selectionmode("$mode $args[0]")) 0 0 0
Condition0%0/9
@args and defined $args[0] and $args[0] eq "not" and is_legal_initial_selectionmode("$mode $args[0]")
!ll&&!rl&&r
000
@args and defined $args[0] and $args[0] eq "not"
!ll&&!rl&&r
000
@args and defined $args[0]
!ll&&!rl&&r
000
MC/DC0%0/4
@args and defined $args[0] and $args[0] eq "not" and is_legal_initial_selectionmode("$mode $args[0]")
@args defined $args[0] $args[0] eq "not" is_legal_initial_selectionmode("$mode $args[0]")
Truth table0%0/5
A and B and C and D
A= @argsB= defined $args[0]C= $args[0] eq "not"D= is_legal_initial_selectionmode("$mode $args[0]")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
306 && is_legal_initial_selectionmode("$mode $args[0]")) {
307 0 $mode .= ' ' . shift @args;
308 }
309  
310 0 push @out, $mode;
311 0 push @verbose, "Mode: '$mode' - ok";
312  
313 0 ▶ return (1, @out) if $mode eq 'all' || $mode eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "all" or $mode eq "none" 0 0 0
Condition0%0/3
$mode eq "all" or $mode eq "none"
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode eq "all" or $mode eq "none"
$mode eq "all" $mode eq "none"
Truth table0%0/3
A or B
A= $mode eq "all"B= $mode eq "none"
ABresult
1X1
011
000
314 0 ▶ return (1, @out) if $mode eq 'one' && @args == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "one" and @args == 0 0 0 0
Condition0%0/3
$mode eq "one" and @args == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$mode eq "one" and @args == 0
$mode eq "one" @args == 0
Truth table0%0/3
A and B
A= $mode eq "one"B= @args == 0
ABresult
0X0
100
111
315 0 ▶ return (0, @verbose, 'Missing method/value pair - not ok') unless @args >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @args >= 2 0 0 0
316 }
317  
318 4 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 10 3 13
319 10 my $argument = shift @args;
320  
321 10 ▶ if (is_field($argument)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_field($argument)) { } 6 4 10
elsif (is_legal_selectionmode($argument)) { } 3 1 4
elsif (defined $argument and $argument eq 'procedure') { } 0 1 1
322 6 push @out, $argument;
323 6 push @verbose, "Field: '$argument' - ok";
324  
325 6 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 6 0 6
326 6 $argument = shift @args;
327 6 push @out, $argument;
328 6 push @verbose, "String: '$argument' - ok";
329 }
330 else {
331 0 push @verbose, 'Missing string - not ok';
332 0 $status = 0;
333 0 last;
334 }
335 }
336 elsif (is_legal_selectionmode($argument)) {
337 3 ▶ if (@args && defined $args[0] && $args[0] eq 'not'
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[0] and $args[0] eq "not" and is_legal_selectionmode("$argument $args[0]")) 0 3 3
Condition33%3/9
@args and defined $args[0] and $args[0] eq "not" and is_legal_selectionmode("$argument $args[0]")
!ll&&!rl&&r
300
@args and defined $args[0] and $args[0] eq "not"
!ll&&!rl&&r
030
@args and defined $args[0]
!ll&&!rl&&r
003
MC/DC0%0/4
@args and defined $args[0] and $args[0] eq "not" and is_legal_selectionmode("$argument $args[0]")
@args defined $args[0] $args[0] eq "not" is_legal_selectionmode("$argument $args[0]")
Truth table20%1/5
A and B and C and D
A= @argsB= defined $args[0]C= $args[0] eq "not"D= is_legal_selectionmode("$argument $args[0]")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
338 && is_legal_selectionmode("$argument $args[0]")) {
339 0 $argument .= ' ' . shift @args;
340 }
341  
342 3 push @out, $argument;
343 3 push @verbose, "Mode: '$argument' - ok";
344  
345 3 ▶ unless (@args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args >= 2) 0 3 3
346 0 push @verbose, 'Missing method/value pair - not ok';
347 0 $status = 0;
348 0 last;
349 }
350 }
351 ▶ elsif (defined $argument && $argument eq 'procedure') {
Condition33%1/3
defined $argument and $argument eq "procedure"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $argument and $argument eq "procedure"
defined $argument $argument eq "procedure"
Truth table33%1/3
A and B
A= defined $argumentB= $argument eq "procedure"
ABresult
0X0
100
111
352 0 push @out, $argument;
353 0 push @verbose, "Field: 'procedure' - ok";
354  
355 0 my $procedure = shift @args;
356 0 ▶ if (ref $procedure eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $procedure eq 'CODE') { } 0 0 0
357 0 ▶ if (_valid_procedure_pointer($procedure)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_valid_procedure_pointer($procedure)) { } 0 0 0
358 0 push @out, $procedure;
359 0 push @verbose, "Procedure pointer: '$procedure' - ok";
360 }
361 else {
362 0 push @verbose, "No such procedure: '$procedure' - not ok";
363 0 $status = 0;
364 0 last;
365 }
366 }
367 else {
368 0 ▶ my $shown = defined $procedure ? $procedure : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $procedure ? : 0 0 0
369 0 push @verbose, "Not a procedure pointer: '$shown' - not ok";
370 0 $status = 0;
371 0 last;
372 }
373 }
374 else {
375 1 ▶ my $shown = defined $argument ? $argument : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $argument ? : 1 0 1
376 1 push @verbose, "Illegal argument: '$shown' - not ok";
377 1 $status = 0;
378 1 last;
379 }
380 }
381  
382 4 ▶ return (1, @out) if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 3 1 4
383 1 return (0, @verbose);
384 }
385  
386 38 ▶sub _selection {
Subroutine _selection: called CC=30 SCAR=39.7
387 38 my ($objects_requested, @args) = @_;
388  
389 38 ▶ if (@args && defined $args[0] && $args[0] eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[0] and $args[0] eq "all") 1 37 38
Condition50%3/6
@args and defined $args[0] and $args[0] eq "all"
!ll&&!rl&&r
0371
@args and defined $args[0]
!ll&&!rl&&r
0038
MC/DC33%1/3
@args and defined $args[0] and $args[0] eq "all"
@args defined $args[0] $args[0] eq "all"
Truth table50%2/4
A and B and C
A= @argsB= defined $args[0]C= $args[0] eq "all"
ABCresult
0XX0
10X0
1100
1111
390 1 my @all = sort(get_postcodes());
391 1 return _maybe_objects($objects_requested, @all);
392 }
393  
394 37 ▶ return if @args && defined $args[0] && $args[0] eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if @args and defined $args[0] and $args[0] eq "none" 1 36 37
Condition50%3/6
@args and defined $args[0] and $args[0] eq "none"
!ll&&!rl&&r
0361
@args and defined $args[0]
!ll&&!rl&&r
0037
MC/DC33%1/3
@args and defined $args[0] and $args[0] eq "none"
@args defined $args[0] $args[0] eq "none"
Truth table50%2/4
A and B and C
A= @argsB= defined $args[0]C= $args[0] eq "none"
ABCresult
0XX0
10X0
1100
1111
395  
396 36 my $limit = 0;
397 36 ▶ if (@args && defined $args[0] && $args[0] eq 'one') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[0] and $args[0] eq "one") 1 35 36
Condition50%3/6
@args and defined $args[0] and $args[0] eq "one"
!ll&&!rl&&r
0351
@args and defined $args[0]
!ll&&!rl&&r
0036
MC/DC33%1/3
@args and defined $args[0] and $args[0] eq "one"
@args defined $args[0] $args[0] eq "one"
Truth table50%2/4
A and B and C
A= @argsB= defined $args[0]C= $args[0] eq "one"
ABCresult
0XX0
10X0
1100
1111
398 1 $limit = 1;
399 1 shift @args;
400 }
401  
402 36 my $mode = 'and';
403 36 my %out;
404 36 my @all = get_postcodes();
405  
406 36 ▶ if (@args) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args) { } 35 1 36
elsif ($limit) { } 1 0 1
407 35 ▶ if (defined $args[0] && is_legal_initial_selectionmode($args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args[0] and is_legal_initial_selectionmode($args[0])) 2 33 35
Condition66%2/3
defined $args[0] and is_legal_initial_selectionmode($args[0])
!ll&&!rl&&r
0332
MC/DC50%1/2
defined $args[0] and is_legal_initial_selectionmode($args[0])
defined $args[0] is_legal_initial_selectionmode($args[0])
Truth table66%2/3
A and B
A= defined $args[0]B= is_legal_initial_selectionmode($args[0])
ABresult
0X0
100
111
408 2 ▶ if (@args > 1 && defined $args[1] && $args[1] eq 'not'
Branch: 1 branch
BranchTrueFalseTotal
if (@args > 1 and defined $args[1] and $args[1] eq 'not' and is_legal_initial_selectionmode("$args[0] $args[1]")) { } 0 2 2
Condition33%3/9
@args > 1 and defined $args[1] and $args[1] eq "not" and is_legal_initial_selectionmode("$args[0] $args[1]")
!ll&&!rl&&r
200
@args > 1 and defined $args[1] and $args[1] eq "not"
!ll&&!rl&&r
020
@args > 1 and defined $args[1]
!ll&&!rl&&r
002
MC/DC0%0/4
@args > 1 and defined $args[1] and $args[1] eq "not" and is_legal_initial_selectionmode("$args[0] $args[1]")
@args > 1 defined $args[1] $args[1] eq "not" is_legal_initial_selectionmode("$args[0] $args[1]")
Truth table20%1/5
A and B and C and D
A= @args > 1B= defined $args[1]C= $args[1] eq "not"D= is_legal_initial_selectionmode("$args[0] $args[1]")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
409 && is_legal_initial_selectionmode("$args[0] $args[1]")) {
410 0 $mode = shift @args;
411 0 $mode .= ' ' . shift @args;
412 }
413 else {
414 2 $mode = shift @args;
415 }
416 }
417  
418 35 ▶ _apply_first_clause($mode, \%out, \@all, \@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
_apply_first_clause($mode, \%out, \@all, \@args) or return 32 3 35
419 32 ▶ $mode = 'and' if $mode eq 'not';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "not" 1 31 32
420 }
421 elsif ($limit) {
422 1 %out = map { $_ => 1 } @all;
423 }
424  
425 33 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 21 33 54
426 21 ▶ if (defined $args[0] && is_legal_selectionmode($args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args[0] and is_legal_selectionmode($args[0])) 17 4 21
Condition66%2/3
defined $args[0] and is_legal_selectionmode($args[0])
!ll&&!rl&&r
0417
MC/DC50%1/2
defined $args[0] and is_legal_selectionmode($args[0])
defined $args[0] is_legal_selectionmode($args[0])
Truth table66%2/3
A and B
A= defined $args[0]B= is_legal_selectionmode($args[0])
ABresult
0X0
100
111
427 17 ▶ if (@args > 1 && defined $args[1] && $args[1] eq 'not'
Branch: 1 branch
BranchTrueFalseTotal
if (@args > 1 and defined $args[1] and $args[1] eq 'not' and is_legal_selectionmode("$args[0] $args[1]")) { } 0 17 17
Condition33%3/9
@args > 1 and defined $args[1] and $args[1] eq "not" and is_legal_selectionmode("$args[0] $args[1]")
!ll&&!rl&&r
1700
@args > 1 and defined $args[1] and $args[1] eq "not"
!ll&&!rl&&r
0170
@args > 1 and defined $args[1]
!ll&&!rl&&r
0017
MC/DC0%0/4
@args > 1 and defined $args[1] and $args[1] eq "not" and is_legal_selectionmode("$args[0] $args[1]")
@args > 1 defined $args[1] $args[1] eq "not" is_legal_selectionmode("$args[0] $args[1]")
Truth table20%1/5
A and B and C and D
A= @args > 1B= defined $args[1]C= $args[1] eq "not"D= is_legal_selectionmode("$args[0] $args[1]")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
428 && is_legal_selectionmode("$args[0] $args[1]")) {
429 0 $mode = shift @args;
430 0 $mode .= ' ' . shift @args;
431 }
432 else {
433 17 $mode = shift @args;
434 }
435 }
436  
437 21 ▶ _apply_next_clause($mode, \%out, \@all, \@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
_apply_next_clause($mode, \%out, \@all, \@args) or return 21 0 21
438 }
439  
440 33 ▶ return unless %out;
Branch: 1 branch
BranchTrueFalseTotal
unless %out 3 30 33
441  
442 30 my @keys = keys %out;
443 30 ▶ my @out = $limit ? ($keys[int rand @keys]) : sort @keys;
Branch: 1 branch
BranchTrueFalseTotal
$limit ? : 1 29 30
444 30 return _maybe_objects($objects_requested, @out);
445 }
446  
447 35 ▶sub _apply_first_clause {
Subroutine _apply_first_clause: called CC=15 SCAR=28.4
448 35 my ($mode, $out, $all, $args) = @_;
449 35 my $field = shift @$args;
450  
451 35 ▶ return _apply_first_procedure_clause($mode, $out, $all, shift @$args)
Branch: 1 branch
BranchTrueFalseTotal
if defined $field and $field eq "procedure" 2 33 35
Condition66%2/3
defined $field and $field eq "procedure"
!ll&&!rl&&r
0332
MC/DC50%1/2
defined $field and $field eq "procedure"
defined $field $field eq "procedure"
Truth table66%2/3
A and B
A= defined $fieldB= $field eq "procedure"
ABresult
0X0
100
111
452 if defined $field && $field eq 'procedure';
453  
454 33 ▶ return 0 unless defined $field && is_field($field);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field and is_field($field) 0 33 33
Condition33%1/3
defined $field and is_field($field)
!ll&&!rl&&r
0033
MC/DC0%0/2
defined $field and is_field($field)
defined $field is_field($field)
Truth table33%1/3
A and B
A= defined $fieldB= is_field($field)
ABresult
0X0
100
111
455  
456 33 my $value = shift @$args;
457 33 ▶ return 0 unless defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 33 33
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
0033
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
458 33 my $regex = _selection_regex($value);
459 33 ▶ return 0 unless $regex;
Branch: 1 branch
BranchTrueFalseTotal
unless $regex 2 31 33
460  
461 31 my $current_field = _field_reader($field);
462  
463 31 for my $postcode (@$all) {
464 158472 my $current_value = $current_field->($postcode);
465 158472 ▶ next unless defined $current_value && length $current_value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $current_value and length $current_value 0 158472 158472
Condition33%1/3
defined $current_value and length $current_value
!ll&&!rl&&r
00158472
MC/DC0%0/2
defined $current_value and length $current_value
defined $current_value length $current_value
Truth table33%1/3
A and B
A= defined $current_valueB= length $current_value
ABresult
0X0
100
111
466  
467 158472 ▶ my $match = $current_value =~ $regex ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$current_value =~ /$regex/ ? : 3545 154927 158472
468 158472 ▶ if ($mode =~ /not/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode =~ /not/) { } 5112 153360 158472
469 5112 ▶ $out->{$postcode}++ unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 5092 20 5112
470 }
471 else {
472 153360 ▶ $out->{$postcode}++ if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 3525 149835 153360
473 }
474 }
475  
476 31 return 1;
477 }
478  
479 2 ▶sub _apply_first_procedure_clause {
Subroutine _apply_first_procedure_clause: called CC=8 SCAR=21.6
480 2 my ($mode, $out, $all, $procedure) = @_;
481 2 ▶ return 0 unless _valid_procedure_pointer($procedure);
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_procedure_pointer($procedure) 0 2 2
482  
483 2 for my $postcode (@$all) {
484 5113 my $match;
485 5113 ▶ eval { $match = $procedure->($postcode) ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
&$procedure($postcode) ? : 1 5111 5112
486 5113 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 5112 5113
487  
488 5112 ▶ if ($mode =~ /not/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode =~ /not/) { } 0 5112 5112
489 0 ▶ $out->{$postcode}++ unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 0 0 0
490 }
491 else {
492 5112 ▶ $out->{$postcode}++ if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 1 5111 5112
493 }
494 }
495  
496 1 return 1;
497 }
498  
499 21 ▶sub _apply_next_clause {
Subroutine _apply_next_clause: called CC=52 SCAR=40.5
500 21 my ($mode, $out, $all, $args) = @_;
501 21 my $field = shift @$args;
502 21 my ($procedure, $current_field, $value);
503  
504 21 ▶ if (defined $field && $field eq 'procedure') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field and $field eq 'procedure') { } 3 18 21
Condition66%2/3
defined $field and $field eq "procedure"
!ll&&!rl&&r
0183
MC/DC50%1/2
defined $field and $field eq "procedure"
defined $field $field eq "procedure"
Truth table66%2/3
A and B
A= defined $fieldB= $field eq "procedure"
ABresult
0X0
100
111
505 3 $procedure = shift @$args;
506 3 ▶ return 0 unless _valid_procedure_pointer($procedure);
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_procedure_pointer($procedure) 0 3 3
507 }
508 else {
509 18 ▶ return 0 unless defined $field && is_field($field);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field and is_field($field) 0 18 18
Condition33%1/3
defined $field and is_field($field)
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $field and is_field($field)
defined $field is_field($field)
Truth table33%1/3
A and B
A= defined $fieldB= is_field($field)
ABresult
0X0
100
111
510  
511 18 $current_field = _field_reader($field);
512 18 $value = shift @$args;
513 18 ▶ return 0 unless defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 18 18
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
514 18 $value = _selection_regex($value);
515 18 ▶ return 0 unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 18 18
516 }
517  
518 21 my @postcodes = _selection_postcodes_for_mode($mode, $out, $all);
519 21 for my $postcode (@postcodes) {
520 53687 my $match;
521  
522 53687 ▶ if ($procedure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($procedure) { } 49 53638 53687
523 49 ▶ eval { $match = $procedure->($postcode) ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
&$procedure($postcode) ? : 47 2 49
524 49 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 49 49
525 }
526 else {
527 53638 my $current_value = $current_field->($postcode);
528 53638 ▶ next unless defined $current_value && length $current_value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $current_value and length $current_value 0 53638 53638
Condition33%1/3
defined $current_value and length $current_value
!ll&&!rl&&r
0053638
MC/DC0%0/2
defined $current_value and length $current_value
defined $current_value length $current_value
Truth table33%1/3
A and B
A= defined $current_valueB= length $current_value
ABresult
0X0
100
111
529 53638 ▶ $match = $current_value =~ $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$current_value =~ /$value/ ? : 1118 52520 53638
530 }
531  
532 53687 ▶ if ($mode eq 'and') {
Branch: 12 branches
BranchTrueFalseTotal
if ($mode eq 'and') { } 1874 51813 53687
elsif ($mode eq 'and not') { } 653 51160 51813
elsif ($mode eq 'nand' or $mode eq 'oldnand') { } 5132 46028 51160
elsif ($mode eq 'nand not' or $mode eq 'oldnand not') { } 5132 40896 46028
elsif ($mode eq 'or') { } 5112 35784 40896
elsif ($mode eq 'or not') { } 5112 30672 35784
elsif ($mode eq 'nor') { } 5112 25560 30672
elsif ($mode eq 'nor not') { } 5112 20448 25560
elsif ($mode eq 'xor') { } 5112 15336 20448
elsif ($mode eq 'xor not') { } 5112 10224 15336
elsif ($mode eq 'xnor') { } 5112 5112 10224
elsif ($mode eq 'xnor not') { } 5112 0 5112
533 1874 ▶ delete $out->{$postcode} unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 945 929 1874
534 }
535 elsif ($mode eq 'and not') {
536 653 ▶ delete $out->{$postcode} if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 188 465 653
537 }
538 # 'oldnand'/'oldnand not' reuse this logic; they differ from 'nand'
539 # only in the iteration set (see _selection_postcodes_for_mode).
540 ▶ elsif ($mode eq 'nand' || $mode eq 'oldnand') {
Condition100%3/3
$mode eq "nand" or $mode eq "oldnand"
l!l&&r!l&&!r
51122046028
MC/DC100%2/2
$mode eq "nand" or $mode eq "oldnand"
$mode eq "nand" $mode eq "oldnand"
Truth table100%3/3
A or B
A= $mode eq "nand"B= $mode eq "oldnand"
ABresult
1X1
011
000
541 5132 ▶ if ($match && $out->{$postcode}) { delete $out->{$postcode} }
Branch: 1 branch
BranchTrueFalseTotal
if ($match and $out->{$postcode}) { } 8 5124 5132
Condition66%2/3
$match and $out->{$postcode}
!ll&&!rl&&r
512408
MC/DC50%1/2
$match and $out->{$postcode}
$match $out->{$postcode}
Truth table66%2/3
A and B
A= $matchB= $out->{$postcode}
ABresult
0X0
100
111
542 5124 else { $out->{$postcode}++ }
543 }
544 ▶ elsif ($mode eq 'nand not' || $mode eq 'oldnand not') {
Condition100%3/3
$mode eq "nand not" or $mode eq "oldnand not"
l!l&&r!l&&!r
51122040896
MC/DC100%2/2
$mode eq "nand not" or $mode eq "oldnand not"
$mode eq "nand not" $mode eq "oldnand not"
Truth table100%3/3
A or B
A= $mode eq "nand not"B= $mode eq "oldnand not"
ABresult
1X1
011
000
545 5132 ▶ if (!$match && $out->{$postcode}) { delete $out->{$postcode} }
Branch: 1 branch
BranchTrueFalseTotal
if (not $match and $out->{$postcode}) { } 32 5100 5132
Condition100%3/3
not $match and $out->{$postcode}
!ll&&!rl&&r
8509232
MC/DC100%2/2
not $match and $out->{$postcode}
not $match $out->{$postcode}
Truth table100%3/3
not(A) and B
A= not $matchB= $out->{$postcode}
ABresult
0X0
100
111
546 5100 else { $out->{$postcode}++ }
547 }
548 elsif ($mode eq 'or') {
549 5112 ▶ $out->{$postcode}++ if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 4 5108 5112
550 }
551 elsif ($mode eq 'or not') {
552 5112 ▶ $out->{$postcode}++ unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 5108 4 5112
553 }
554 elsif ($mode eq 'nor') {
555 5112 ▶ if (!$match && !$out->{$postcode}) { $out->{$postcode}++ }
Branch: 1 branch
BranchTrueFalseTotal
if (not $match || $out->{$postcode}) { } 5092 20 5112
Condition100%3/3
$match || $out->{$postcode}
l!l&&r!l&&!r
4165092
MC/DC100%2/2
$match || $out->{$postcode}
$match $out->{$postcode}
Truth table100%3/3
A || B
A= $matchB= $out->{$postcode}
ABresult
1X1
011
000
556 20 ▶ else { delete $out->{$postcode} if $out->{$postcode} }
Branch: 1 branch
BranchTrueFalseTotal
if $out->{$postcode} 20 0 20
557 }
558 elsif ($mode eq 'nor not') {
559 0 ▶ if ($match && !$out->{$postcode}) { $out->{$postcode}++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($match and not $out->{$postcode}) { } 0 5112 5112
Condition66%2/3
$match and not $out->{$postcode}
!ll&&!rl&&r
510840
MC/DC0%0/2
$match and not $out->{$postcode}
$match not $out->{$postcode}
Truth table66%2/3
A and not(B)
A= $matchB= not $out->{$postcode}
ABresult
0X0
100
111
560 5112 ▶ else { delete $out->{$postcode} if $out->{$postcode} }
Branch: 1 branch
BranchTrueFalseTotal
if $out->{$postcode} 20 5092 5112
561 }
562 elsif ($mode eq 'xor') {
563 5112 ▶ next unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 5108 4 5112
564 4 ▶ $out->{$postcode} ? delete $out->{$postcode} : $out->{$postcode}++;
Branch: 1 branch
BranchTrueFalseTotal
$out->{$postcode} ? : 4 0 4
565 }
566 elsif ($mode eq 'xor not') {
567 5112 ▶ next if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 4 5108 5112
568 5108 ▶ $out->{$postcode} ? delete $out->{$postcode} : $out->{$postcode}++;
Branch: 1 branch
BranchTrueFalseTotal
$out->{$postcode} ? : 16 5092 5108
569 }
570 elsif ($mode eq 'xnor') {
571 5112 ▶ my $boolean = $out->{$postcode} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$out->{$postcode} ? : 20 5092 5112
572 5112 ▶ $match == $boolean ? $out->{$postcode}++ : delete $out->{$postcode};
Branch: 1 branch
BranchTrueFalseTotal
$match == $boolean ? : 5096 16 5112
573 }
574 elsif ($mode eq 'xnor not') {
575 5112 ▶ my $boolean = $out->{$postcode} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$out->{$postcode} ? : 20 5092 5112
576 5112 ▶ $match != $boolean ? $out->{$postcode}++ : delete $out->{$postcode};
Branch: 1 branch
BranchTrueFalseTotal
$match != $boolean ? : 16 5096 5112
577 }
578 }
579  
580 21 return 1;
581 }
582  
583 17 ▶sub _load_data {
Subroutine _load_data: called CC=4 SCAR=13.9
584 17 ▶ $LOADED_FROM_ENV = defined $ENV{$DATA_ENV} && length $ENV{$DATA_ENV} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} && length $ENV{$Geo::Postcodes::NO::DATA_ENV} ? : 3 14 17
Condition66%2/3
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENV}
!ll&&!rl&&r
1403
MC/DC50%1/2
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENV}
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} length $ENV{$Geo::Postcodes::NO::DATA_ENV}
Truth table66%2/3
A and B
A= defined $ENV{$Geo::Postcodes::NO::DATA_ENV}B= length $ENV{$Geo::Postcodes::NO::DATA_ENV}
ABresult
0X0
100
111
585  
586 17 my $path = _data_path();
587 17 my $encoding = _data_encoding();
588 17 $LOADED_DATA_FILE = $path;
589 17 $LOADED_DATA_ENCODING = $encoding;
590 17 my ($records) = Geo::Postcodes::NO::Check::read_records(
591 $path,
592 $encoding,
593 county_prefixes => [ keys %COUNTY ],
594 decode_subject => "postcode data $path",
595 line_errors_include_path => 1,
596 );
597  
598 17 for my $record (@$records) {
599 76682 my ($postcode, $location, $borough_number, $borough, $category) = @$record;
600 76682 my $type = $BRING_CATEGORY_TO_TYPE{$category};
601  
602 76682 $LOCATION{$postcode} = $location;
603 76682 $BOROUGH_NUMBER{$postcode} = $borough_number;
604 76682 $BOROUGH{$borough_number} = $borough;
605 76682 $TYPE{$postcode} = $type;
606 76682 $BRING_CATEGORY{$postcode} = $category;
607 }
608 }
609  
610 17 ▶sub _data_path {
Subroutine _data_path: called CC=4 SCAR=14.1
611 17 ▶ return $ENV{$DATA_ENV} if defined $ENV{$DATA_ENV} && length $ENV{$DATA_ENV};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{$Geo::Postcodes::NO::DATA_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENV} 3 14 17
Condition66%2/3
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENV}
!ll&&!rl&&r
1403
MC/DC50%1/2
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENV}
defined $ENV{$Geo::Postcodes::NO::DATA_ENV} length $ENV{$Geo::Postcodes::NO::DATA_ENV}
Truth table66%2/3
A and B
A= defined $ENV{$Geo::Postcodes::NO::DATA_ENV}B= length $ENV{$Geo::Postcodes::NO::DATA_ENV}
ABresult
0X0
100
111
612  
613 14 ▶ my $module_path = $INC{'Geo/Postcodes/NO.pm'} || __FILE__;
Condition50%1/2
$INC{'Geo/Postcodes/NO.pm'} || __FILE__
l!l
140
MC/DC0%0/1
$INC{'Geo/Postcodes/NO.pm'} || __FILE__
$INC{'Geo/Postcodes/NO.pm'}
Truth table50%1/2
A
A= $INC{'Geo/Postcodes/NO.pm'}
Aresult
11
00
614 14 my (undef, $module_dir) = File::Spec->splitpath($module_path);
615 14 return File::Spec->catfile($module_dir, 'NO', $DATA_FILE);
616 }
617  
618 17 ▶sub _data_encoding {
Subroutine _data_encoding: called CC=3 SCAR=11.1
619 return $ENV{$DATA_ENCODING_ENV}
620 17 ▶ if defined $ENV{$DATA_ENCODING_ENV} && length $ENV{$DATA_ENCODING_ENV};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV} 1 16 17
Condition66%2/3
defined $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV}
!ll&&!rl&&r
1601
MC/DC50%1/2
defined $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV} and length $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV}
defined $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV} length $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV}
Truth table66%2/3
A and B
A= defined $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV}B= length $ENV{$Geo::Postcodes::NO::DATA_ENCODING_ENV}
ABresult
0X0
100
111
621 16 return $DATA_ENCODING;
622 }
623  
624 49 ▶sub _field_reader {
Subroutine _field_reader: called CC=8 SCAR=21.0
625 49 my $field = shift;
626  
627 49 ▶ return \&postcode_of if $field eq 'postcode';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "postcode" 25 24 49
628 24 ▶ return \&location_of if $field eq 'location';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "location" 2 22 24
629 22 ▶ return \&borough_number_of if $field eq 'borough_number';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "borough_number" 0 22 22
630 22 ▶ return \&borough_of if $field eq 'borough';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "borough" 1 21 22
631 21 ▶ return \&county_of if $field eq 'county';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "county" 3 18 21
632 18 ▶ return \&type_of if $field eq 'type';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "type" 17 1 18
633 1 ▶ return \&type_verbose_of if $field eq 'type_verbose';
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "type_verbose" 1 0 1
634  
635 0 return;
636 }
637  
638 31 ▶sub _maybe_objects {
Subroutine _maybe_objects: called CC=2 SCAR=6.9
639 31 my ($objects_requested, @postcodes) = @_;
640 31 ▶ return @postcodes unless $objects_requested;
Branch: 1 branch
BranchTrueFalseTotal
unless $objects_requested 27 4 31
641 4 return map { __PACKAGE__->new($_) } @postcodes;
642 }
643  
644 6508 ▶sub _object_field {
Subroutine _object_field: called CC=3 SCAR=11.7
645 6508 my ($self, $field) = @_;
646 6508 ▶ return unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 6508 6508
647 6508 ▶ return exists $self->{$field} ? $self->{$field} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$field} ? : 6508 0 6508
648 }
649  
650 38 ▶sub _shift_class_invocant {
Subroutine _shift_class_invocant: called CC=5 SCAR=16.2
651 38 my $args = shift;
652 38 ▶ return 0 unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 38 38
653 38 ▶ return 0 unless defined $args->[0] && !ref $args->[0] && $args->[0] eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->[0] and not ref $args->[0] and $args->[0] eq __PACKAGE__ 34 4 38
Condition83%5/6
defined $args->[0] and not ref $args->[0] and $args->[0] eq __PACKAGE__
!ll&&!rl&&r
1334
defined $args->[0] and not ref $args->[0]
!ll&&!rl&&r
0137
MC/DC66%2/3
defined $args->[0] and not ref $args->[0] and $args->[0] eq __PACKAGE__
defined $args->[0] not ref $args->[0] $args->[0] eq __PACKAGE__
Truth table75%3/4
A and not(B) and C
A= defined $args->[0]B= not ref $args->[0]C= $args->[0] eq __PACKAGE__
ABCresult
0XX0
10X0
1100
1111
654 4 shift @$args;
655 4 return 1;
656 }
657  
658 12 ▶sub _looks_like_invocant {
Subroutine _looks_like_invocant: called CC=4 SCAR=14.1
659 12 my $value = shift;
660 12 ▶ return 1 if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 12 12
661 12 ▶ return 1 if defined $value && $value =~ /\AGeo::Postcodes::NO(?:\z|::)/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $value =~ /\AGeo::Postcodes::NO(?:\z|::)/ 8 4 12
Condition66%2/3
defined $value and $value =~ /\AGeo::Postcodes::NO(?:\z|::)/
!ll&&!rl&&r
048
MC/DC50%1/2
defined $value and $value =~ /\AGeo::Postcodes::NO(?:\z|::)/
defined $value $value =~ /\AGeo::Postcodes::NO(?:\z|::)/
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /\AGeo::Postcodes::NO(?:\z|::)/
ABresult
0X0
100
111
662 4 return 0;
663 }
664  
665 5 ▶sub _valid_procedure_pointer {
Subroutine _valid_procedure_pointer: called CC=3 SCAR=11.7
666 5 my $ptr = shift;
667 5 ▶ return 0 unless ref $ptr eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ptr eq "CODE" 0 5 5
668 5 ▶ return defined &$ptr ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined &$ptr ? : 5 0 5
669 }
670  
671 21 ▶sub _selection_postcodes_for_mode {
Subroutine _selection_postcodes_for_mode: called CC=5 SCAR=16.1
672 21 my ($mode, $out, $all) = @_;
673  
674 21 ▶ return keys %$out
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "and" or $mode eq "and not" or $mode eq "oldnand" or $mode eq "oldnand not" 11 10 21
Condition100%9/9
$mode eq "and" or $mode eq "and not" or $mode eq "oldnand" or $mode eq "oldnand not"
l!l&&r!l&&!r
10110
$mode eq "and" or $mode eq "and not" or $mode eq "oldnand"
l!l&&r!l&&!r
9111
$mode eq "and" or $mode eq "and not"
l!l&&r!l&&!r
7212
MC/DC100%4/4
$mode eq "and" or $mode eq "and not" or $mode eq "oldnand" or $mode eq "oldnand not"
$mode eq "and" $mode eq "and not" $mode eq "oldnand" $mode eq "oldnand not"
Truth table100%5/5
A or B or C or D
A= $mode eq "and"B= $mode eq "and not"C= $mode eq "oldnand"D= $mode eq "oldnand not"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
675 if $mode eq 'and'
676 || $mode eq 'and not'
677 || $mode eq 'oldnand'
678 || $mode eq 'oldnand not';
679  
680 10 return @$all;
681 }
682  
683 51 ▶sub _selection_regex {
Subroutine _selection_regex: called CC=2 SCAR=6.9
684 51 my $value = shift;
685 51 $value =~ s/%/.*/g;
686  
687 51 my $regex = eval { qr/^$value$/i };
688 51 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 49 51
689 49 return $regex;
690 }
691  
692 17 1;
693  
694 __END__
« blib/lib/Geo/Postcodes/NO/Check.pm ↑ Summary eg/selection.pl »