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 = '8.00'; |
20
|
55
|
|
|
55
|
|
28570
|
use Moo::Role; |
|
55
|
|
|
|
|
122
|
|
|
55
|
|
|
|
|
362
|
|
21
|
|
|
|
|
|
|
requires 'api_version'; |
22
|
|
|
|
|
|
|
requires 'api'; |
23
|
|
|
|
|
|
|
|
24
|
55
|
|
|
55
|
|
19328
|
use Scalar::Util qw(looks_like_number); |
|
55
|
|
|
|
|
153
|
|
|
55
|
|
|
|
|
3589
|
|
25
|
55
|
|
|
55
|
|
341
|
use Search::Elasticsearch::Util qw(throw); |
|
55
|
|
|
|
|
117
|
|
|
55
|
|
|
|
|
430
|
|
26
|
55
|
|
|
55
|
|
14568
|
use namespace::clean; |
|
55
|
|
|
|
|
130
|
|
|
55
|
|
|
|
|
341
|
|
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
|
|
|
|
|
|
|
integer => \&_num, |
38
|
|
|
|
|
|
|
float => \&_num, |
39
|
|
|
|
|
|
|
double => \&_num, |
40
|
|
|
|
|
|
|
"number|string" => \&_numOrString, |
41
|
|
|
|
|
|
|
"boolean|long" => \&_booleanOrLong |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#=================================== |
45
|
|
|
|
|
|
|
sub _bool { |
46
|
|
|
|
|
|
|
#=================================== |
47
|
0
|
|
|
0
|
|
0
|
my $val = _detect_bool(@_); |
48
|
0
|
0
|
0
|
|
|
0
|
return ( $val && $val ne 'false' ) ? 'true' : 'false'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#=================================== |
52
|
|
|
|
|
|
|
sub _detect_bool { |
53
|
|
|
|
|
|
|
#=================================== |
54
|
0
|
|
|
0
|
|
0
|
my $val = shift; |
55
|
0
|
0
|
|
|
|
0
|
return '' unless defined $val; |
56
|
0
|
0
|
|
|
|
0
|
if ( ref $val eq 'SCALAR' ) { |
|
|
0
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
return 'false' if $$val eq 0; |
58
|
0
|
0
|
|
|
|
0
|
return 'true' if $$val eq 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) { |
61
|
0
|
0
|
|
|
|
0
|
return "$val" ? 'true' : 'false'; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
0
|
return "$val"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#=================================== |
67
|
|
|
|
|
|
|
sub _list { |
68
|
|
|
|
|
|
|
#=================================== |
69
|
0
|
|
|
|
|
0
|
return join ",", map { _detect_bool($_) } # |
70
|
0
|
0
|
|
0
|
|
0
|
ref $_[0] eq 'ARRAY' ? @{ $_[0] } : $_[0]; |
|
0
|
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#=================================== |
74
|
|
|
|
|
|
|
sub _num { |
75
|
|
|
|
|
|
|
#=================================== |
76
|
0
|
|
|
0
|
|
0
|
return 0 + $_[0]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#=================================== |
80
|
|
|
|
|
|
|
sub _string { |
81
|
|
|
|
|
|
|
#=================================== |
82
|
0
|
|
|
0
|
|
0
|
return "$_[0]"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#=================================== |
86
|
|
|
|
|
|
|
sub _numOrString { |
87
|
|
|
|
|
|
|
#=================================== |
88
|
0
|
0
|
|
0
|
|
0
|
if (looks_like_number($_[0])) { |
89
|
0
|
|
|
|
|
0
|
return _num($_[0]); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
0
|
return _string($_[0]); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#=================================== |
95
|
|
|
|
|
|
|
sub _booleanOrLong { |
96
|
|
|
|
|
|
|
#=================================== |
97
|
0
|
0
|
|
0
|
|
0
|
if (looks_like_number($_[0])) { |
98
|
0
|
|
|
|
|
0
|
return _num($_[0]); |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
0
|
my $val = _detect_bool(@_); |
101
|
0
|
0
|
0
|
|
|
0
|
return ( $val && $val ne 'false' ) ? 'true' : 'false'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#=================================== |
105
|
|
|
|
|
|
|
sub _qs_init { |
106
|
|
|
|
|
|
|
#=================================== |
107
|
55
|
|
|
55
|
|
153
|
my $class = shift; |
108
|
55
|
|
|
|
|
99
|
my $API = shift; |
109
|
55
|
|
|
|
|
2441
|
for my $spec ( keys %$API ) { |
110
|
22825
|
|
|
|
|
33014
|
my $qs = $API->{$spec}{qs}; |
111
|
22825
|
|
|
|
|
51129
|
for my $param ( keys %$qs ) { |
112
|
|
|
|
|
|
|
my $handler = $Handler{ $qs->{$param} } |
113
|
|
|
|
|
|
|
or throw( "Internal", |
114
|
|
|
|
|
|
|
"Unknown type <" |
115
|
132550
|
50
|
|
|
|
225286
|
. $qs->{$param} |
116
|
|
|
|
|
|
|
. "> for param <$param> in API <$spec>" ); |
117
|
132550
|
|
|
|
|
187139
|
$qs->{$param} = $handler; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# ABSTRACT: Provides common functionality for API implementations |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |