lib/App/ElasticSearch/Utilities/QueryString/Ranges.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 78.8% 41 / 52 CC 6 SCAR 16.5
CC
6
Cov
77%
handle_token
9.4
BEGIN
1.0
BEGIN
1.0
CRAP 5.2
« lib/App/ElasticSearch/Utilities/QueryString/Nested.pm ↑ Summary script/es-index-fields.pl »
1 package App::ElasticSearch::Utilities::QueryString::Ranges;
2 # ABSTRACT: Implement parsing comparison operators to Equivalent Lucene syntax
3  
4 2 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '9.1'; # VERSION
8  
9 2 ▶use CLI::Helpers qw(:output);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 with 'App::ElasticSearch::Utilities::QueryString::Plugin';
14  
15 1 ▶sub _build_priority { 20; }
Subroutine _build_priority: called CC=1 SCAR=0.0
16  
17 1 my %Operators = (
18 '<' => { side => 'left', op => 'lt' },
19 '<=' => { side => 'left', op => 'lte' },
20 '>' => { side => 'right', op => 'gt' },
21 '>=' => { side => 'right', op => 'gte' },
22 );
23 1 my $op_match = join('|', map { quotemeta } sort { length $b <=> length $a } keys %Operators);
24  
25  
26 7 ▶sub handle_token {
Subroutine handle_token: called CC=6 SCAR=22.4
Pod undocumented
27 7 my ($self,$token) = @_;
28  
29 7 debug(sprintf "%s - evaluating token '%s'", $self->name, $token);
30 7 my ($k,$v) = split /:/, $token, 2;
31  
32 7 ▶ return unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 7 7
33  
34 7 my %sides = ();
35 7 my %range = ();
36 7 foreach my $range (split /\,/, $v) {
37 7 ▶ if( my($symbol,$value) = ( $range =~ /^($op_match)(.+)$/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $range =~ /^($op_match)(.+)$/u) 0 7 7
38 0 my $side = $Operators{$symbol}->{side};
39 # Invalid query if two left or right operators
40 die "attempted to set more than one $side-side operator in Range: $token"
41 0 ▶ if $sides{$side};
Branch: 1 branch
BranchTrueFalseTotal
if $sides{$side} 0 0 0
42 0 $sides{$side} = 1;
43 0 $range{$Operators{$symbol}->{op}} = $value;
44 }
45 }
46  
47 7 ▶ return unless scalar keys %range;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %range 7 0 7
48  
49 0 return { condition => { range => { $k => \%range } } };
50 }
51  
52 # Return True;
53 1 1;
54  
55 __END__
« lib/App/ElasticSearch/Utilities/QueryString/Nested.pm ↑ Summary script/es-index-fields.pl »