| 1 | # Licensed to Elasticsearch B.V under one or more agreements. | ||||||||||||||||||||||||||||
| 2 | # Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||||||||||||||||||||||||||||
| 3 | # See the LICENSE file in the project root for more information | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Search::Elasticsearch::Role::API; | ||||||||||||||||||||||||||||
| 6 | 55 | $Search::Elasticsearch::Role::API::VERSION = '7.30_1'; # TRIAL | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 55 | $Search::Elasticsearch::Role::API::VERSION = '7.301'; | |||||||||||||||||||||||||||
| 9 | 55 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 55 | requires 'api_version'; | |||||||||||||||||||||||||||
| 11 | 55 | requires 'api'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 55 | ▶ | use Search::Elasticsearch::Util qw(throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 55 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 55 | our %Handler = ( | |||||||||||||||||||||||||||
| 17 | string => \&_string, | ||||||||||||||||||||||||||||
| 18 | time => \&_string, | ||||||||||||||||||||||||||||
| 19 | date => \&_string, | ||||||||||||||||||||||||||||
| 20 | list => \&_list, | ||||||||||||||||||||||||||||
| 21 | boolean => \&_bool, | ||||||||||||||||||||||||||||
| 22 | enum => \&_list, | ||||||||||||||||||||||||||||
| 23 | number => \&_num, | ||||||||||||||||||||||||||||
| 24 | int => \&_num, | ||||||||||||||||||||||||||||
| 25 | float => \&_num, | ||||||||||||||||||||||||||||
| 26 | double => \&_num, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #=================================== | ||||||||||||||||||||||||||||
| 30 | sub _bool { | ||||||||||||||||||||||||||||
| 31 | #=================================== | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $val = _detect_bool(@_); | ||||||||||||||||||||||||||
|
Subroutine
_bool: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | return ( $val && $val ne 'false' ) ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$val and $val ne "false"
MC/DC0%0/2
$val and $val ne "false"
$val
$val ne "false"
Truth table0%0/3
A and B
A= $valB= $val ne "false"
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #=================================== | ||||||||||||||||||||||||||||
| 37 | sub _detect_bool { | ||||||||||||||||||||||||||||
| 38 | #=================================== | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $val = shift; | ||||||||||||||||||||||||||
|
Subroutine
_detect_bool: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return '' unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( ref $val eq 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return 'false' if $$val eq 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return 'true' if $$val eq 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return "$val" ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | return "$val"; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | #=================================== | ||||||||||||||||||||||||||||
| 52 | sub _list { | ||||||||||||||||||||||||||||
| 53 | #=================================== | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return join ",", map { _detect_bool($_) } # | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | ref $_[0] eq 'ARRAY' ? @{ $_[0] } : $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_list: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | #=================================== | ||||||||||||||||||||||||||||
| 59 | sub _num { | ||||||||||||||||||||||||||||
| 60 | #=================================== | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return 0 + $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_num: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | #=================================== | ||||||||||||||||||||||||||||
| 65 | sub _string { | ||||||||||||||||||||||||||||
| 66 | #=================================== | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return "$_[0]"; | ||||||||||||||||||||||||||
|
Subroutine
_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | #=================================== | ||||||||||||||||||||||||||||
| 71 | sub _qs_init { | ||||||||||||||||||||||||||||
| 72 | #=================================== | ||||||||||||||||||||||||||||
| 73 | 55 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_qs_init: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 74 | 55 | my $API = shift; | |||||||||||||||||||||||||||
| 75 | 55 | for my $spec ( keys %$API ) { | |||||||||||||||||||||||||||
| 76 | 14905 | my $qs = $API->{$spec}{qs}; | |||||||||||||||||||||||||||
| 77 | 14905 | for my $param ( keys %$qs ) { | |||||||||||||||||||||||||||
| 78 | my $handler = $Handler{ $qs->{$param} } | ||||||||||||||||||||||||||||
| 79 | or throw( "Internal", | ||||||||||||||||||||||||||||
| 80 | "Unknown type <" | ||||||||||||||||||||||||||||
| 81 | 93225 | ▶ | . $qs->{$param} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | . "> for param <$param> in API <$spec>" ); | ||||||||||||||||||||||||||||
| 83 | 93225 | $qs->{$param} = $handler; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 55 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # ABSTRACT: Provides common functionality for API implementations | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||