line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Licensed to Elasticsearch B.V. under one or more contributor |
2
|
|
|
|
|
|
|
# license agreements. See the NOTICE file distributed with |
3
|
|
|
|
|
|
|
# this work for additional information regarding copyright |
4
|
|
|
|
|
|
|
# ownership. Elasticsearch B.V. licenses this file to you under |
5
|
|
|
|
|
|
|
# the Apache License, Version 2.0 (the "License"); you may |
6
|
|
|
|
|
|
|
# not use this file except in compliance with the License. |
7
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, |
12
|
|
|
|
|
|
|
# software distributed under the License is distributed on an |
13
|
|
|
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14
|
|
|
|
|
|
|
# KIND, either express or implied. See the License for the |
15
|
|
|
|
|
|
|
# specific language governing permissions and limitations |
16
|
|
|
|
|
|
|
# under the License. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Search::Elasticsearch::Role::API; |
19
|
|
|
|
|
|
|
$Search::Elasticsearch::Role::API::VERSION = '7.717'; |
20
|
55
|
|
|
55
|
|
26084
|
use Moo::Role; |
|
55
|
|
|
|
|
107
|
|
|
55
|
|
|
|
|
754
|
|
21
|
|
|
|
|
|
|
requires 'api_version'; |
22
|
|
|
|
|
|
|
requires 'api'; |
23
|
|
|
|
|
|
|
|
24
|
55
|
|
|
55
|
|
16883
|
use Scalar::Util qw(looks_like_number); |
|
55
|
|
|
|
|
116
|
|
|
55
|
|
|
|
|
3041
|
|
25
|
55
|
|
|
55
|
|
284
|
use Search::Elasticsearch::Util qw(throw); |
|
55
|
|
|
|
|
94
|
|
|
55
|
|
|
|
|
356
|
|
26
|
55
|
|
|
55
|
|
13317
|
use namespace::clean; |
|
55
|
|
|
|
|
94
|
|
|
55
|
|
|
|
|
329
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our %Handler = ( |
29
|
|
|
|
|
|
|
string => \&_string, |
30
|
|
|
|
|
|
|
time => \&_string, |
31
|
|
|
|
|
|
|
date => \&_string, |
32
|
|
|
|
|
|
|
list => \&_list, |
33
|
|
|
|
|
|
|
boolean => \&_bool, |
34
|
|
|
|
|
|
|
enum => \&_list, |
35
|
|
|
|
|
|
|
number => \&_num, |
36
|
|
|
|
|
|
|
int => \&_num, |
37
|
|
|
|
|
|
|
float => \&_num, |
38
|
|
|
|
|
|
|
double => \&_num, |
39
|
|
|
|
|
|
|
"number|string" => \&_numOrString, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#=================================== |
43
|
|
|
|
|
|
|
sub _bool { |
44
|
|
|
|
|
|
|
#=================================== |
45
|
0
|
|
|
0
|
|
0
|
my $val = _detect_bool(@_); |
46
|
0
|
0
|
0
|
|
|
0
|
return ( $val && $val ne 'false' ) ? 'true' : 'false'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#=================================== |
50
|
|
|
|
|
|
|
sub _detect_bool { |
51
|
|
|
|
|
|
|
#=================================== |
52
|
0
|
|
|
0
|
|
0
|
my $val = shift; |
53
|
0
|
0
|
|
|
|
0
|
return '' unless defined $val; |
54
|
0
|
0
|
|
|
|
0
|
if ( ref $val eq 'SCALAR' ) { |
|
|
0
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
0
|
return 'false' if $$val eq 0; |
56
|
0
|
0
|
|
|
|
0
|
return 'true' if $$val eq 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) { |
59
|
0
|
0
|
|
|
|
0
|
return "$val" ? 'true' : 'false'; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
0
|
return "$val"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#=================================== |
65
|
|
|
|
|
|
|
sub _list { |
66
|
|
|
|
|
|
|
#=================================== |
67
|
0
|
|
|
|
|
0
|
return join ",", map { _detect_bool($_) } # |
68
|
0
|
0
|
|
0
|
|
0
|
ref $_[0] eq 'ARRAY' ? @{ $_[0] } : $_[0]; |
|
0
|
|
|
|
|
0
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#=================================== |
72
|
|
|
|
|
|
|
sub _num { |
73
|
|
|
|
|
|
|
#=================================== |
74
|
0
|
|
|
0
|
|
0
|
return 0 + $_[0]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#=================================== |
78
|
|
|
|
|
|
|
sub _string { |
79
|
|
|
|
|
|
|
#=================================== |
80
|
0
|
|
|
0
|
|
0
|
return "$_[0]"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#=================================== |
84
|
|
|
|
|
|
|
sub _numOrString { |
85
|
|
|
|
|
|
|
#=================================== |
86
|
0
|
0
|
|
0
|
|
0
|
if (looks_like_number($_[0])) { |
87
|
0
|
|
|
|
|
0
|
return _num($_[0]); |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
return _string($_[0]); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#=================================== |
93
|
|
|
|
|
|
|
sub _qs_init { |
94
|
|
|
|
|
|
|
#=================================== |
95
|
55
|
|
|
55
|
|
153
|
my $class = shift; |
96
|
55
|
|
|
|
|
89
|
my $API = shift; |
97
|
55
|
|
|
|
|
1943
|
for my $spec ( keys %$API ) { |
98
|
22330
|
|
|
|
|
30722
|
my $qs = $API->{$spec}{qs}; |
99
|
22330
|
|
|
|
|
43753
|
for my $param ( keys %$qs ) { |
100
|
|
|
|
|
|
|
my $handler = $Handler{ $qs->{$param} } |
101
|
|
|
|
|
|
|
or throw( "Internal", |
102
|
|
|
|
|
|
|
"Unknown type <" |
103
|
132055
|
50
|
|
|
|
181999
|
. $qs->{$param} |
104
|
|
|
|
|
|
|
. "> for param <$param> in API <$spec>" ); |
105
|
132055
|
|
|
|
|
150457
|
$qs->{$param} = $handler; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# ABSTRACT: Provides common functionality for API implementations |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |