Compat/QueryParser.pm

filter: Statementstmt 96.1% 252 / 262 Branchbran 94.4% 153 / 162 Conditioncond 85.7% 54 / 63 MC/DCmcdc 72.2% 26 / 36 Subroutinesub 96.5% 28 / 29 Podpod 100% 3 / 3 totaltotal 92.9% 516 / 555 CC 106 SCAR 21.2
CC
106
Cov
94%
__ANON__
19.0
_dump_tokens
12.0
_FUZZY
12.0
CRAP 8.3
« Client/Compat.pm ↑ Summary Compat/ScrolledSearch.pm »
1 package Search::Elasticsearch::Compat::QueryParser;
2 1 $Search::Elasticsearch::Compat::QueryParser::VERSION = '0.10';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Search::Elasticsearch::Util qw(parse_params throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 @Search::Elasticsearch::Error::QueryParser::ISA
8 1 = 'Search::Elasticsearch::Error';
9  
10 # ABSTRACT: Check or filter query strings
11  
12  
13 #===================================
14 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
15 #===================================
16 2 my ( $proto, $params ) = parse_params(@_);
17 2 ▶ my $class = ref $proto || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
18 2 $params = {
19 escape_reserved => 0,
20 fields => 0,
21 wildcard_prefix => 1,
22 allow_bool => 1,
23 allow_boost => 1,
24 allow_fuzzy => 1,
25 allow_slop => 1,
26 allow_ranges => 0,
27 %$params,
28 };
29 2 return bless {
30 _default_opts => $params,
31 _opts => $params,
32 }, $class;
33 }
34  
35 #===================================
36 97 ▶sub filter {
Subroutine filter: called CC=1 SCAR=0.0
Pod documented
37 #===================================
38 97 my $self = shift;
39 97 my $text = shift;
40 97 my ( undef, $opts ) = parse_params( $self, @_ );
41 97 $opts->{fix} = 1;
42 97 return $self->_parse( $text, $opts );
43 }
44  
45 #===================================
46 97 ▶sub check {
Subroutine check: called CC=1 SCAR=0.0
Pod documented
47 #===================================
48 97 my $self = shift;
49 97 my $text = shift;
50 97 my ( undef, $opts ) = parse_params( $self, @_ );
51 97 $opts->{fix} = 0;
52 97 return $self->_parse( $text, $opts );
53 }
54  
55 #===================================
56 194 ▶sub _parse {
Subroutine _parse: called CC=5 SCAR=16.1
57 #===================================
58 194 my $self = shift;
59 194 my $text = shift;
60 194 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 194 194
61 194 utf8::upgrade($text);
62  
63 194 my $opts = shift;
64 194 $self->{_opts} = { %{ $self->{_default_opts} }, %$opts };
65  
66 194 $self->{_tokeniser} = $self->_init_tokeniser($text);
67 194 $self->{_tokens} = [];
68 194 $self->{_stack} = [ {} ];
69 194 $self->{_start_pos} = 0;
70 194 $self->{_done} = 0;
71  
72 194 my $phrase;
73 194 eval {
74 194 $phrase = $self->_multi_clauses;
75 die "Syntax error\n"
76 144 ▶ unless $self->{_done} || $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_done"} or $opts->{"fix"} 8 136 144
Condition66%2/3
$self->{"_done"} or $opts->{"fix"}
l!l&&r!l&&!r
13608
MC/DC50%1/2
$self->{"_done"} or $opts->{"fix"}
$self->{"_done"} $opts->{"fix"}
Truth table66%2/3
A or B
A= $self->{"_done"}B= $opts->{"fix"}
ABresult
1X1
011
000
77 };
78 194 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 58 136 194
79 58 $@ =~ s/\n$/:\n/;
80 58 substr( $text, $self->{_start_pos}, 0, ' <HERE> ' );
81 58 throw( 'QueryParser', "$@$text" );
82 }
83 136 return $phrase;
84 }
85  
86 #===================================
87 0 ▶sub _dump_tokens {
Subroutine _dump_tokens: not called CC=3 SCAR=24.8
88 #===================================
89 0 my $self = shift;
90 0 my $text = shift;
91 0 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
92 0 utf8::upgrade($text);
93  
94 0 my $tokeniser = $self->_init_tokeniser($text);
95  
96 0 ▶ while ( my $next = $tokeniser->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = &$tokeniser()) 0 0 0
97 printf "TOKEN: %-15s VARS: %s\n", shift @$next,
98 0 join( ', ', grep { defined $_ } @$next );
99 }
100 }
101  
102 #===================================
103 1140 ▶sub _next_token {
Subroutine _next_token: called CC=3 SCAR=11.0
104 #===================================
105 1140 my $self = shift;
106 1140 my $next = shift @{ $self->{_tokens} }
107 1140 ▶ || $self->{_tokeniser}->();
Condition100%3/3
shift @{$$self{'_tokens'};} || $self->{'_tokeniser'}->()
l!l&&r!l&&!r
160723257
MC/DC100%2/2
shift @{$$self{'_tokens'};} || $self->{'_tokeniser'}->()
shift @{$$self{'_tokens'};} $self->{'_tokeniser'}->()
Truth table100%3/3
A || B
A= shift @{$$self{'_tokens'};}B= $self->{'_tokeniser'}->()
ABresult
1X1
011
000
108 1140 ▶ return $next if $next;
Branch: 1 branch
BranchTrueFalseTotal
if $next 883 257 1140
109 257 $self->{_done} = 1;
110 257 return;
111 }
112  
113 #===================================
114 174 ▶sub _return_token {
Subroutine _return_token: called CC=1 SCAR=0.0
115 #===================================
116 174 my $self = shift;
117 174 push @{ $self->{_tokens} }, shift;
118 174 $self->{_done} = 0;
119 }
120  
121 # 1 = Can follow
122 # 0 = Cannot follow, drop token and try next token
123 # undef = Cannot follow, stop looking
124  
125 1 my %Clauses = (
126 _LPAREN => 1,
127 _PLUS_MINUS => 1,
128 _EXISTS => 1,
129 _FIELD => 1,
130 _TERM => 1,
131 _PHRASE => 1,
132 _WILDTERM => 1,
133 _RANGE => 1,
134 _NOT => 1,
135 _AND_OR => 1,
136 _SPACE => 1,
137 _RESERVED => 1,
138 _ESCAPE => 1,
139 );
140  
141 1 my %Boost = ( _BOOST => 1 );
142  
143 1 my %Allowed = (
144 _CLAUSE => \%Clauses,
145 _LPAREN => { %Clauses, _RPAREN => 1 },
146 _AND_OR => { %Clauses, _AND_OR => 0 },
147 _NOT => { %Clauses, _NOT => 0, _AND_OR => 0 },
148 _PLUS_MINUS => {
149 %Clauses,
150 _NOT => 0,
151 _AND_OR => 0,
152 _PLUS_MINUS => 0,
153 _SPACE => undef,
154 },
155 _FIELD => {
156 _LPAREN => 1,
157 _TERM => 1,
158 _WILDTERM => 1,
159 _PHRASE => 1,
160 _RANGE => 1,
161 },
162 _PHRASE => { _BOOST => 1, _FUZZY => 1 },
163 _TERM => { _BOOST => 1, _FUZZY => 1 },
164 _WILDTERM => \%Boost,
165 _RANGE => \%Boost,
166 _FUZZY => \%Boost,
167 _RPAREN => \%Boost,
168 _EXISTS => \%Boost,
169 _BOOST => {},
170 _SPACE => {},
171 _RESERVED => {},
172 _ESCAPE => {},
173 );
174  
175 #===================================
176 942 ▶sub _parse_context {
Subroutine _parse_context: called CC=6 SCAR=17.9
177 #===================================
178 942 my $self = shift;
179 942 my $context = shift;
180 942 my $allowed = $Allowed{$context};
181  
182 TOKEN: {
183 942 ▶ my $token = $self->_next_token or return;
Branch: 1 branch
BranchTrueFalseTotal
my $token = $self->_next_token or return 856 255 1111
184  
185 856 my ( $type, @args ) = @$token;
186 856 ▶ if ( $allowed->{$type} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($allowed->{$type}) { } 666 190 856
elsif (defined $allowed->{$type}) { } 17 173 190
187 666 ▶ redo TOKEN if $type eq '_SPACE';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "_SPACE" 160 506 666
188 506 return $self->$type(@args);
189 }
190 elsif ( defined $allowed->{$type} ) {
191 17 ▶ die "Syntax error\n" unless $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opts"}{"fix"} 8 9 17
192 9 redo TOKEN;
193 }
194 else {
195 173 $self->_return_token($token);
196 173 return undef;
197 }
198 }
199 }
200  
201 #===================================
202 214 ▶sub _multi_clauses {
Subroutine _multi_clauses: called CC=6 SCAR=17.9
203 #===================================
204 214 my $self = shift;
205 214 my @clauses;
206 214 while (1) {
207 515 my $clause = $self->_parse_context('_CLAUSE');
208 465 ▶ if ( !defined $clause ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $clause) 173 292 465
209 last
210 173 if @{ $self->{_stack} } > 1
211 || !$self->{_opts}{fix}
212 173 ▶ || $self->{_done};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"_stack"};} > 1 or not $self->{"_opts"}{"fix"} or $self->{"_done"} 164 9 173
Condition100%6/6
@{$self->{"_stack"};} > 1 or not $self->{"_opts"}{"fix"} or $self->{"_done"}
l!l&&r!l&&!r
68969
@{$self->{"_stack"};} > 1 or not $self->{"_opts"}{"fix"}
l!l&&r!l&&!r
2147105
MC/DC100%3/3
@{$self->{"_stack"};} > 1 or not $self->{"_opts"}{"fix"} or $self->{"_done"}
@{$self->{"_stack"};} > 1 not $self->{"_opts"}{"fix"} $self->{"_done"}
Truth table100%4/4
A or not(B) or C
A= @{$self->{"_stack"};} > 1B= not $self->{"_opts"}{"fix"}C= $self->{"_done"}
ABCresult
1XX1
01X1
0011
0000
213 9 $self->_next_token;
214 9 next;
215 }
216 292 ▶ next unless length $clause;
Branch: 1 branch
BranchTrueFalseTotal
unless length $clause 28 264 292
217 264 push @clauses, $clause;
218 264 $self->{_stack}[-1]{clauses}++;
219 }
220 164 return join( ' ', @clauses );
221 }
222  
223 #===================================
224 45 ▶sub _AND_OR {
Subroutine _AND_OR: called CC=8 SCAR=20.8
225 #===================================
226 45 my $self = shift;
227 45 my $op = shift;
228 45 my $opts = $self->{_opts};
229  
230 45 ▶ unless ( $self->{_stack}[-1]{clauses} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_stack"}[-1]{"clauses"}) 8 37 45
231 8 ▶ return '' if $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"fix"} 4 4 8
232 4 die "$op must be preceded by another clause\n";
233 }
234 37 ▶ unless ( $opts->{allow_bool} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"allow_bool"}) 3 34 37
235 3 ▶ die qq("$op" not allowed) unless $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"fix"} 1 2 3
236 2 return '';
237 }
238  
239 34 my $next = $self->_parse_context('_AND_OR');
240 30 ▶ return "$op $next"
Branch: 1 branch
BranchTrueFalseTotal
if defined $next and length $next 26 4 30
Condition66%2/3
defined $next and length $next
!ll&&!rl&&r
4026
MC/DC50%1/2
defined $next and length $next
defined $next length $next
Truth table66%2/3
A and B
A= defined $nextB= length $next
ABresult
0X0
100
111
241 if defined $next && length $next;
242  
243 4 ▶ return '' if $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"fix"} 2 2 4
244 2 die "$op must be followed by a clause\n";
245 }
246  
247 #===================================
248 27 ▶sub _NOT {
Subroutine _NOT: called CC=8 SCAR=20.8
249 #===================================
250 27 my $self = shift;
251 27 my $op = shift;
252  
253 27 my $opts = $self->{_opts};
254 27 ▶ unless ( $opts->{allow_bool} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"allow_bool"}) 3 24 27
255 3 ▶ die qq("$op" not allowed) unless $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"fix"} 1 2 3
256 2 return '';
257 }
258  
259 24 my $next = $self->_parse_context('_NOT');
260 21 ▶ $next = '' unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 4 17 21
261  
262 die "$op cannot be followed by + or -"
263 21 ▶ if $next =~ s/^[+-]+// && !$opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $next =~ s/^[+-]+// and not $opts->{"fix"} 1 20 21
Condition100%3/3
$next =~ s/^[+-]+// and not $opts->{"fix"}
!ll&&!rl&&r
1911
MC/DC100%2/2
$next =~ s/^[+-]+// and not $opts->{"fix"}
$next =~ s/^[+-]+// not $opts->{"fix"}
Truth table100%3/3
A and not(B)
A= $next =~ s/^[+-]+//B= not $opts->{"fix"}
ABresult
0X0
100
111
264  
265 20 ▶ return "$op $next"
Branch: 1 branch
BranchTrueFalseTotal
if length $next 16 4 20
266 if length $next;
267  
268 4 ▶ return '' if $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"fix"} 2 2 4
269 2 die "$op must be followed by a clause\n";
270 }
271  
272 #===================================
273 21 ▶sub _PLUS_MINUS {
Subroutine _PLUS_MINUS: called CC=4 SCAR=13.9
274 #===================================
275 21 my $self = shift;
276 21 my $op = shift;
277 21 my $next = $self->_parse_context('_PLUS_MINUS');
278  
279 20 ▶ return "$op$next" if defined $next && length $next;
Branch: 1 branch
BranchTrueFalseTotal
if defined $next and length $next 17 3 20
Condition66%2/3
defined $next and length $next
!ll&&!rl&&r
3017
MC/DC50%1/2
defined $next and length $next
defined $next length $next
Truth table66%2/3
A and B
A= defined $nextB= length $next
ABresult
0X0
100
111
280  
281 3 ▶ return '' if $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_opts"}{"fix"} 2 1 3
282 1 die "$op must be followed by a clause";
283 }
284  
285 #===================================
286 20 ▶sub _LPAREN {
Subroutine _LPAREN: called CC=7 SCAR=19.5
287 #===================================
288 20 my $self = shift;
289 20 push @{ $self->{_stack} }, {};
290 20 my $clause = $self->_multi_clauses;
291  
292 20 my $close = ')';
293 20 my $rparen = $self->_next_token;
294 20 ▶ if ( $rparen && $rparen->[0] eq '_RPAREN' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rparen and $rparen->[0] eq '_RPAREN') { } 18 2 20
elsif ($self->{'_opts'}{'fix'}) { } 1 1 2
Condition66%2/3
$rparen and $rparen->[0] eq "_RPAREN"
!ll&&!rl&&r
2018
MC/DC50%1/2
$rparen and $rparen->[0] eq "_RPAREN"
$rparen $rparen->[0] eq "_RPAREN"
Truth table66%2/3
A and B
A= $rparenB= $rparen->[0] eq "_RPAREN"
ABresult
0X0
100
111
295 18 ▶ my $next = $self->_parse_context('_RPAREN') || '';
Condition100%2/2
$self->_parse_context('_RPAREN') || ''
l!l
711
MC/DC100%1/1
$self->_parse_context('_RPAREN') || ''
$self->_parse_context('_RPAREN')
Truth table100%2/2
A
A= $self->_parse_context('_RPAREN')
Aresult
11
00
296 18 ▶ $close .= $next if $next;
Branch: 1 branch
BranchTrueFalseTotal
if $next 7 11 18
297 18 pop @{ $self->{_stack} };
298 }
299 elsif ( $self->{_opts}{fix} ) {
300 1 $self->_return_token($rparen);
301 }
302 else {
303 1 die "Missing closing parenthesis\n";
304 }
305 19 ▶ return $clause ? "(${clause}${close}" : '';
Branch: 1 branch
BranchTrueFalseTotal
$clause ? : 19 0 19
306 }
307  
308 #===================================
309 46 ▶sub _BOOST {
Subroutine _BOOST: called CC=6 SCAR=17.9
310 #===================================
311 46 my $self = shift;
312 46 ▶ unless ( $self->{_opts}{allow_boost} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_opts"}{"allow_boost"}) 7 39 46
313 7 ▶ die "Boost not allowed" unless $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opts"}{"fix"} 3 4 7
314 4 return '';
315 }
316 39 my $val = shift;
317 39 ▶ unless ( defined $val && length $val ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val and length $val) 4 35 39
Condition66%2/3
defined $val and length $val
!ll&&!rl&&r
4035
MC/DC50%1/2
defined $val and length $val
defined $val length $val
Truth table66%2/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
318 4 ▶ return '' if $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_opts"}{"fix"} 2 2 4
319 2 die "Missing boost value\n";
320 }
321 35 return "^$val";
322 }
323  
324 #===================================
325 40 ▶sub _FUZZY {
Subroutine _FUZZY: called CC=12 SCAR=24.8
326 #===================================
327 40 my $self = shift;
328 40 my $fuzzy = shift;
329 40 my $opts = $self->{_opts};
330 40 my $fix = $opts->{fix};
331  
332 40 ▶ if ( $self->{current} eq '_PHRASE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'} eq '_PHRASE') { } 21 19 40
333  
334 # phrase slop
335 21 ▶ if ( $opts->{allow_slop} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'allow_slop'}) { } 17 4 21
336 17 ▶ $fuzzy = int( $fuzzy || 0 );
Condition100%2/2
$fuzzy || 0
l!l
134
MC/DC100%1/1
$fuzzy || 0
$fuzzy
Truth table100%2/2
A
A= $fuzzy
Aresult
11
00
337 17 ▶ $fuzzy = $fuzzy ? "~$fuzzy" : '';
Branch: 1 branch
BranchTrueFalseTotal
$fuzzy ? : 11 6 17
338 }
339 else {
340 4 ▶ die "Phrase slop not allowed\n" unless $fix;
Branch: 1 branch
BranchTrueFalseTotal
unless $fix 2 2 4
341 2 $fuzzy = '';
342 }
343 }
344 else {
345  
346 # fuzzy
347 19 ▶ if ( $opts->{allow_fuzzy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'allow_fuzzy'}) { } 15 4 19
348 15 ▶ if ( defined $fuzzy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fuzzy) { } 11 4 15
349 11 ▶ if ( $fuzzy <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fuzzy <= 1) { } 9 2 11
350 9 $fuzzy = "~$fuzzy";
351 }
352 else {
353 2 ▶ die "Fuzzy value must be between 0.0 and 1.0\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $fix 1 1 2
354 unless $fix;
355 1 $fuzzy = '';
356 }
357 }
358 else {
359 4 $fuzzy = '~';
360 }
361 }
362 else {
363 4 ▶ die "Fuzzy not allowed\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $fix 2 2 4
364 unless $fix;
365 2 $fuzzy = '';
366 }
367 }
368  
369 35 ▶ my $next = $self->_parse_context('_FUZZY') || '';
Condition100%2/2
$self->_parse_context('_FUZZY') || ''
l!l
1221
MC/DC100%1/1
$self->_parse_context('_FUZZY') || ''
$self->_parse_context('_FUZZY')
Truth table100%2/2
A
A= $self->_parse_context('_FUZZY')
Aresult
11
00
370 33 return "$fuzzy$next";
371 }
372  
373 #===================================
374 28 ▶sub _PHRASE {
Subroutine _PHRASE: called CC=2 SCAR=6.9
375 #===================================
376 28 my $self = shift;
377 28 my $string = shift;
378  
379 28 local $self->{current} = '_PHRASE';
380 28 ▶ my $next = $self->_parse_context('_PHRASE') || '';
Condition100%2/2
$self->_parse_context('_PHRASE') || ''
l!l
1312
MC/DC100%1/1
$self->_parse_context('_PHRASE') || ''
$self->_parse_context('_PHRASE')
Truth table100%2/2
A
A= $self->_parse_context('_PHRASE')
Aresult
11
00
381  
382 25 return qq("$string"$next);
383 }
384  
385 #===================================
386 14 ▶sub _EXISTS {
Subroutine _EXISTS: called CC=8 SCAR=20.8
387 #===================================
388 14 my $self = shift;
389 14 my $prefix = shift;
390 14 my $field = shift;
391  
392 14 my $opts = $self->{_opts};
393 14 ▶ my $next = $self->_parse_context('_EXISTS') || '';
Condition100%2/2
$self->_parse_context('_EXISTS') || ''
l!l
410
MC/DC100%1/1
$self->_parse_context('_EXISTS') || ''
$self->_parse_context('_EXISTS')
Truth table100%2/2
A
A= $self->_parse_context('_EXISTS')
Aresult
11
00
394 14 ▶ unless ( $opts->{fields}
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"fields"} and !ref($opts->{"fields"}) || $opts->{"fields"}{$field}) 5 9 14
Condition100%6/6
$opts->{"fields"} and !ref($opts->{"fields"}) || $opts->{"fields"}{$field}
!ll&&!rl&&r
329
not ref $opts->{"fields"} or $opts->{"fields"}{$field}
l!l&&r!l&&!r
722
MC/DC100%3/3
$opts->{"fields"} and !ref($opts->{"fields"}) || $opts->{"fields"}{$field}
$opts->{"fields"} not ref $opts->{"fields"} $opts->{"fields"}{$field}
Truth table100%4/4
A and not(B) or C
A= $opts->{"fields"}B= not ref $opts->{"fields"}C= $opts->{"fields"}{$field}
ABCresult
0XX0
1000
11X1
1011
395 and ( !ref $opts->{fields} || $opts->{fields}{$field} ) )
396 {
397 5 ▶ return '' if $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"fix"} 3 2 5
398 2 die qq("Field "$field" not allowed);
399 }
400  
401 9 ▶ return "$prefix:$field$next"
Branch: 1 branch
BranchTrueFalseTotal
if $field 6 3 9
402 if $field;
403 3 ▶ return '' if $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_opts"}{"fix"} 2 1 3
404 1 die "Missing field name for $prefix\n";
405 }
406  
407 #===================================
408 18 ▶sub _FIELD {
Subroutine _FIELD: called CC=8 SCAR=22.1
409 #===================================
410 18 my $self = shift;
411 18 my $field = shift;
412  
413 18 my $opts = $self->{_opts};
414 18 my $next = $self->_parse_context('_FIELD');
415  
416 18 ▶ unless ( defined $next && length $next ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $next and length $next) 0 18 18
Condition33%1/3
defined $next and length $next
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $next and length $next
defined $next length $next
Truth table33%1/3
A and B
A= defined $nextB= length $next
ABresult
0X0
100
111
417 die "Missing clause after field $field\n"
418 0 ▶ unless $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"fix"} 0 0 0
419 0 return '';
420 }
421  
422 return "$field:$next"
423 if $opts->{fields}
424 18 ▶ and !ref $opts->{fields} || $opts->{fields}{$field};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"fields"} and !ref($opts->{"fields"}) || $opts->{"fields"}{$field} 8 10 18
Condition100%6/6
$opts->{"fields"} and !ref($opts->{"fields"}) || $opts->{"fields"}{$field}
!ll&&!rl&&r
288
not ref $opts->{"fields"} or $opts->{"fields"}{$field}
l!l&&r!l&&!r
448
MC/DC100%3/3
$opts->{"fields"} and !ref($opts->{"fields"}) || $opts->{"fields"}{$field}
$opts->{"fields"} not ref $opts->{"fields"} $opts->{"fields"}{$field}
Truth table100%4/4
A and not(B) or C
A= $opts->{"fields"}B= not ref $opts->{"fields"}C= $opts->{"fields"}{$field}
ABCresult
0XX0
1000
11X1
1011
425  
426 die qq("Field "$field" not allowed)
427 10 ▶ unless $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"fix"} 5 5 10
428  
429 5 return $next;
430 }
431  
432 #===================================
433 196 ▶sub _TERM {
Subroutine _TERM: called CC=2 SCAR=6.9
434 #===================================
435 196 my $self = shift;
436 196 local $self->{current} = '_TERM';
437 196 ▶ my $next = $self->_parse_context('_TERM') || '';
Condition100%2/2
$self->_parse_context('_TERM') || ''
l!l
19170
MC/DC100%1/1
$self->_parse_context('_TERM') || ''
$self->_parse_context('_TERM')
Truth table100%2/2
A
A= $self->_parse_context('_TERM')
Aresult
11
00
438 189 return shift(@_) . $next;
439 }
440  
441 #===================================
442 13 ▶sub _WILDTERM {
Subroutine _WILDTERM: called CC=6 SCAR=17.9
443 #===================================
444 13 my $self = shift;
445 13 my $term = shift;
446 13 my $min = $self->{_opts}{wildcard_prefix};
447 13 ▶ my $next = $self->_parse_context('_WILDTERM') || '';
Condition50%1/2
$self->_parse_context('_WILDTERM') || ''
l!l
013
MC/DC0%0/1
$self->_parse_context('_WILDTERM') || ''
$self->_parse_context('_WILDTERM')
Truth table50%1/2
A
A= $self->_parse_context('_WILDTERM')
Aresult
11
00
448 13 ▶ if ( $term !~ /^[^*?]{$min}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($term =~ /^[^*?]{$min}/) 5 8 13
449 die "Wildcard cannot have * or ? "
450 . (
451 $min == 1 ? 'as first character' : "in first $min characters" )
452 5 ▶ unless $self->{_opts}{fix};
Branch: 2 branches
BranchTrueFalseTotal
unless $self->{"_opts"}{"fix"} 2 3 5
$min == 1 ? : 1 1 2
453 3 $term =~ s/[*?].*//;
454 3 ▶ return '' unless length $term;
Branch: 1 branch
BranchTrueFalseTotal
unless length $term 1 2 3
455 }
456 10 return "$term$next";
457 }
458  
459 #===================================
460 26 ▶sub _RANGE {
Subroutine _RANGE: called CC=6 SCAR=17.9
461 #===================================
462 26 my $self = shift;
463 26 my ( $open, $close, $from, $to ) = @_;
464 26 my $opts = $self->{_opts};
465 26 ▶ my $next = $self->_parse_context('_RANGE') || '';
Condition100%2/2
$self->_parse_context('_RANGE') || ''
l!l
422
MC/DC100%1/1
$self->_parse_context('_RANGE') || ''
$self->_parse_context('_RANGE')
Truth table100%2/2
A
A= $self->_parse_context('_RANGE')
Aresult
11
00
466 26 ▶ unless ( $opts->{allow_ranges} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"allow_ranges"}) 2 24 26
467 die "Ranges not allowed\n"
468 2 ▶ unless $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"fix"} 1 1 2
469 1 return '';
470 }
471 24 ▶ unless ( defined $to ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $to) 4 20 24
472 4 ▶ die "Malformed range\n" unless $opts->{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"fix"} 2 2 4
473 2 return '';
474 }
475 20 return "$open$from TO $to$close$next";
476 }
477  
478 #===================================
479 10 ▶sub _RESERVED {
Subroutine _RESERVED: called CC=3 SCAR=11.0
480 #===================================
481 10 my $self = shift;
482 10 my $char = shift;
483 die "Reserved character $char\n"
484 10 ▶ unless $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opts"}{"fix"} 5 5 10
485 return $self->{_opts}{escape_reserved}
486 5 ▶ ? "\\$char"
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_opts'}{'escape_reserved'} ? : 1 4 5
487 : '';
488 }
489  
490 #===================================
491 2 ▶sub _ESCAPE {
Subroutine _ESCAPE: called CC=2 SCAR=6.9
492 #===================================
493 2 my $self = shift;
494 die qq(Cannot end with "\\"\n)
495 2 ▶ unless $self->{_opts}{fix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opts"}{"fix"} 1 1 2
496 1 return '';
497 }
498  
499 1 my $DECIMAL = qr/[0-9]+(?:[.][0-9]+)?/;
500 1 my $NUM_CHAR = qr/[0-9]/;
501 1 my $ESC_CHAR = qr/\\./;
502 1 my $WS = qr/[ \t\n\r\x{3000}]/;
503 1 my $TERM_START_CHAR
504 = qr/[^ \t\n\r\x{3000}+\-!():^[\]"{}~*?\\&|] | $ESC_CHAR/x;
505 1 my $TERM_CHAR = qr/$TERM_START_CHAR |$ESC_CHAR | [-+]/x;
506 1 my $QUOTE_RANGE = qr/(?: " (?: \\" | [^"] )* ")/x;
507 1 my $RANGE_SEP = qr/ \s+ (?: TO \s+)?/x;
508  
509 #===================================
510 207 ▶sub _init_tokeniser {
Subroutine _init_tokeniser: called CC=1 SCAR=0.0
511 #===================================
512 207 my $self = shift;
513 207 my $text = shift;
514  
515 207 my $weak_self = $self;
516 207 Scalar::Util::weaken($weak_self);
517 1046 ▶ return sub {
Subroutine __ANON__: called CC=19 SCAR=29.4
518 TOKEN: {
519 1046 ▶ $weak_self->{_start_pos} = pos($text) || 0;
Condition100%2/2
pos $text || 0
l!l
839207
MC/DC100%1/1
pos $text || 0
pos $text
Truth table100%2/2
A
A= pos $text
Aresult
11
00
520 1046 ▶ return ['_SPACE']
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G$WS/cg 180 866 1046
521 if $text =~ m/\G$WS/gc;
522 866 ▶ return [ '_AND_OR', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G(AND\b | && | OR\b | \|{2})/cgx 61 805 866
523 if $text =~ m/\G(AND\b | && | OR\b | \|{2})/gcx;
524 805 ▶ return [ '_NOT', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G(NOT\b | !)/cgx 31 774 805
525 if $text =~ m/\G(NOT\b | !)/gcx;
526 774 ▶ return [ '_PLUS_MINUS', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G([-+])/cg 26 748 774
527 if $text =~ m/\G([-+])/gc;
528 748 ▶ return ['_LPAREN']
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G[(]/cg 21 727 748
529 if $text =~ m/\G[(]/gc;
530 727 ▶ return ['_RPAREN']
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G[)]/cg 21 706 727
531 if $text =~ m/\G[)]/gc;
532 706 ▶ return [ '_BOOST', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G\^($DECIMAL)?/cg 52 654 706
533 if $text =~ m/\G\^($DECIMAL)?/gc;
534 654 ▶ return [ '_FUZZY', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G[~]($DECIMAL)?/cg 51 603 654
535 if $text =~ m/\G[~]($DECIMAL)?/gc;
536 603 ▶ return [ '_PHRASE', $1, $2 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G " ( (?: $ESC_CHAR | [^"\\])*) "/cgx 29 574 603
537 if $text =~ m/\G " ( (?: $ESC_CHAR | [^"\\])*) "/gcx;
538 574 ▶ return [ '_EXISTS', $1, $2 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G (_exists_|_missing_): ((?:$TERM_START_CHAR $TERM_CHAR*)?) /cgx 16 558 574
539 if $text =~ m/\G
540 (_exists_|_missing_):
541 ((?:$TERM_START_CHAR $TERM_CHAR*)?)
542 /gcx;
543 558 ▶ return [ '_FIELD', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G ($TERM_START_CHAR $TERM_CHAR*):/cgx 19 539 558
544 if $text =~ m/\G ($TERM_START_CHAR $TERM_CHAR*):/gcx;
545 539 ▶ return [ '_TERM', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G ( $TERM_START_CHAR $TERM_CHAR*) (?!$TERM_CHAR | [*?]) /cgx 201 338 539
546 if $text =~ m/\G
547 ( $TERM_START_CHAR $TERM_CHAR*)
548 (?!$TERM_CHAR | [*?])
549 /gcx;
550 338 ▶ return [ '_WILDTERM', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G ( (?:$TERM_START_CHAR | [*?]) (?:$TERM_CHAR | [*?])* )/cgx 17 321 338
551 if $text =~ m/\G (
552 (?:$TERM_START_CHAR | [*?])
553 (?:$TERM_CHAR | [*?])*
554 )/gcx;
555 321 ▶ return [ '_RANGE', '[', ']', $1, $2 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G \[ ( $QUOTE_RANGE | [^ \]]+ ) (?: $RANGE_SEP ( $QUOTE_RANGE | [^ \]]* ) )? \] /cgx 28 293 321
556 if $text =~ m/\G \[
557 ( $QUOTE_RANGE | [^ \]]+ )
558 (?: $RANGE_SEP
559 ( $QUOTE_RANGE | [^ \]]* )
560 )?
561 \]
562 /gcx;
563 293 ▶ return [ '_RANGE', '{', '}', $1, $2 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G \{ ( $QUOTE_RANGE | [^ }]+ ) (?: $RANGE_SEP ( $QUOTE_RANGE | [^ }]* ) )? \} /cgx 2 291 293
564 if $text =~ m/\G \{
565 ( $QUOTE_RANGE | [^ }]+ )
566 (?:
567 $RANGE_SEP
568 ( $QUOTE_RANGE | [^ }]* )
569 )?
570 \}
571 /gcx;
572  
573 291 ▶ return [ '_RESERVED', $1 ]
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G ( ["&|!(){}[\]~^:+\-] )/cgx 18 273 291
574 if $text =~ m/\G ( ["&|!(){}[\]~^:+\-] )/gcx;
575  
576 273 ▶ return ['_ESCAPE']
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\G\\$/cg 3 270 273
577 if $text =~ m/\G\\$/gc;
578 }
579 270 return;
580  
581 207 };
582 }
583  
584 1 1;
585  
586 __END__
« Client/Compat.pm ↑ Summary Compat/ScrolledSearch.pm »