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::Util; |
19
|
|
|
|
|
|
|
$Search::Elasticsearch::Util::VERSION = '8.00'; |
20
|
67
|
|
|
67
|
|
1065
|
use Moo; |
|
67
|
|
|
|
|
153
|
|
|
67
|
|
|
|
|
366
|
|
21
|
67
|
|
|
67
|
|
126990
|
use Search::Elasticsearch::Error(); |
|
67
|
|
|
|
|
375
|
|
|
67
|
|
|
|
|
2032
|
|
22
|
67
|
|
|
67
|
|
448
|
use Scalar::Util qw(blessed); |
|
67
|
|
|
|
|
132
|
|
|
67
|
|
|
|
|
3498
|
|
23
|
67
|
|
|
67
|
|
415
|
use Module::Runtime qw(compose_module_name is_module_name use_module); |
|
67
|
|
|
|
|
151
|
|
|
67
|
|
|
|
|
436
|
|
24
|
67
|
|
|
|
|
469
|
use Sub::Exporter -setup => { |
25
|
|
|
|
|
|
|
exports => [ qw( |
26
|
|
|
|
|
|
|
parse_params |
27
|
|
|
|
|
|
|
to_list |
28
|
|
|
|
|
|
|
load_plugin |
29
|
|
|
|
|
|
|
new_error |
30
|
|
|
|
|
|
|
throw |
31
|
|
|
|
|
|
|
upgrade_error |
32
|
|
|
|
|
|
|
is_compat |
33
|
|
|
|
|
|
|
) |
34
|
|
|
|
|
|
|
] |
35
|
67
|
|
|
67
|
|
42895
|
}; |
|
67
|
|
|
|
|
698227
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#=================================== |
38
|
|
|
|
|
|
|
sub to_list { |
39
|
|
|
|
|
|
|
#=================================== |
40
|
304
|
100
|
|
304
|
0
|
1140
|
grep {defined} ref $_[0] eq 'ARRAY' ? @{ $_[0] } : @_; |
|
297
|
|
|
|
|
1315
|
|
|
72
|
|
|
|
|
226
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#=================================== |
44
|
|
|
|
|
|
|
sub parse_params { |
45
|
|
|
|
|
|
|
#=================================== |
46
|
562
|
|
|
562
|
0
|
1180
|
my $self = shift; |
47
|
562
|
|
|
|
|
997
|
my %params; |
48
|
562
|
100
|
|
|
|
1764
|
if ( @_ % 2 ) { |
49
|
150
|
50
|
|
|
|
584
|
throw( |
50
|
|
|
|
|
|
|
"Param", |
51
|
|
|
|
|
|
|
'Expecting a HASH ref or a list of key-value pairs', |
52
|
|
|
|
|
|
|
{ params => \@_ } |
53
|
|
|
|
|
|
|
) unless ref $_[0] eq 'HASH'; |
54
|
150
|
|
|
|
|
308
|
%params = %{ shift() }; |
|
150
|
|
|
|
|
781
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
412
|
|
|
|
|
1623
|
%params = @_; |
58
|
|
|
|
|
|
|
} |
59
|
562
|
|
|
|
|
1953
|
return ( $self, \%params ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#=================================== |
63
|
|
|
|
|
|
|
sub load_plugin { |
64
|
|
|
|
|
|
|
#=================================== |
65
|
700
|
|
|
700
|
0
|
1501
|
my ( $base, $spec ) = @_; |
66
|
700
|
|
66
|
|
|
2270
|
$spec ||= "+$base"; |
67
|
700
|
50
|
|
|
|
2248
|
return $spec if blessed $spec; |
68
|
|
|
|
|
|
|
|
69
|
700
|
|
|
|
|
1226
|
my ( $class, $version ); |
70
|
700
|
50
|
|
|
|
1690
|
if ( ref $spec eq 'ARRAY' ) { |
71
|
0
|
|
|
|
|
0
|
( $class, $version ) = @$spec; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
700
|
|
|
|
|
1130
|
$class = $spec; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
700
|
100
|
|
|
|
2552
|
unless ( $class =~ s/\A\+// ) { |
78
|
468
|
|
|
|
|
1596
|
$class = compose_module_name( $base, $class ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
700
|
50
|
|
|
|
24450
|
$version ? use_module( $class, $version ) : use_module($class); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#=================================== |
85
|
|
|
|
|
|
|
sub throw { |
86
|
|
|
|
|
|
|
#=================================== |
87
|
88
|
|
|
88
|
0
|
692
|
my ( $type, $msg, $vars ) = @_; |
88
|
88
|
|
|
|
|
522
|
die Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#=================================== |
92
|
|
|
|
|
|
|
sub new_error { |
93
|
|
|
|
|
|
|
#=================================== |
94
|
29
|
|
|
29
|
0
|
75
|
my ( $type, $msg, $vars ) = @_; |
95
|
29
|
|
|
|
|
102
|
return Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#=================================== |
99
|
|
|
|
|
|
|
sub upgrade_error { |
100
|
|
|
|
|
|
|
#=================================== |
101
|
46
|
|
|
46
|
0
|
120
|
my ( $error, $vars ) = @_; |
102
|
|
|
|
|
|
|
return |
103
|
46
|
50
|
33
|
|
|
536
|
ref($error) && $error->isa('Search::Elasticsearch::Error') |
|
|
|
0
|
|
|
|
|
104
|
|
|
|
|
|
|
? $error |
105
|
|
|
|
|
|
|
: Search::Elasticsearch::Error->new( "Internal", $error, $vars || {}, |
106
|
|
|
|
|
|
|
1 ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#=================================== |
110
|
|
|
|
|
|
|
sub is_compat { |
111
|
|
|
|
|
|
|
#=================================== |
112
|
200
|
|
|
200
|
0
|
519
|
my ( $attr, $one, $two ) = @_; |
113
|
200
|
50
|
|
|
|
603
|
my $role |
114
|
|
|
|
|
|
|
= $one->does('Search::Elasticsearch::Role::Is_Sync') |
115
|
|
|
|
|
|
|
? 'Search::Elasticsearch::Role::Is_Sync' |
116
|
|
|
|
|
|
|
: 'Search::Elasticsearch::Role::Is_Async'; |
117
|
|
|
|
|
|
|
|
118
|
200
|
50
|
|
|
|
4986
|
return if eval { $two->does($role); }; |
|
200
|
|
|
|
|
657
|
|
119
|
0
|
|
0
|
|
|
|
my $class = ref($two) || $two; |
120
|
0
|
|
|
|
|
|
die "$attr ($class) does not do $role"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# ABSTRACT: A utility class for internal use by Search::Elasticsearch |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |