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 = '7.717'; |
20
|
67
|
|
|
67
|
|
981
|
use Moo; |
|
67
|
|
|
|
|
142
|
|
|
67
|
|
|
|
|
296
|
|
21
|
67
|
|
|
67
|
|
104784
|
use Search::Elasticsearch::Error(); |
|
67
|
|
|
|
|
150
|
|
|
67
|
|
|
|
|
1818
|
|
22
|
67
|
|
|
67
|
|
552
|
use Scalar::Util qw(blessed); |
|
67
|
|
|
|
|
139
|
|
|
67
|
|
|
|
|
3291
|
|
23
|
67
|
|
|
67
|
|
358
|
use Module::Runtime qw(compose_module_name is_module_name use_module); |
|
67
|
|
|
|
|
135
|
|
|
67
|
|
|
|
|
424
|
|
24
|
67
|
|
|
|
|
450
|
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
|
|
36924
|
}; |
|
67
|
|
|
|
|
574916
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#=================================== |
38
|
|
|
|
|
|
|
sub to_list { |
39
|
|
|
|
|
|
|
#=================================== |
40
|
304
|
100
|
|
304
|
0
|
958
|
grep {defined} ref $_[0] eq 'ARRAY' ? @{ $_[0] } : @_; |
|
297
|
|
|
|
|
1192
|
|
|
72
|
|
|
|
|
192
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#=================================== |
44
|
|
|
|
|
|
|
sub parse_params { |
45
|
|
|
|
|
|
|
#=================================== |
46
|
562
|
|
|
562
|
0
|
1005
|
my $self = shift; |
47
|
562
|
|
|
|
|
842
|
my %params; |
48
|
562
|
100
|
|
|
|
1561
|
if ( @_ % 2 ) { |
49
|
150
|
50
|
|
|
|
537
|
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
|
|
|
|
|
228
|
%params = %{ shift() }; |
|
150
|
|
|
|
|
709
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
412
|
|
|
|
|
1268
|
%params = @_; |
58
|
|
|
|
|
|
|
} |
59
|
562
|
|
|
|
|
1629
|
return ( $self, \%params ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#=================================== |
63
|
|
|
|
|
|
|
sub load_plugin { |
64
|
|
|
|
|
|
|
#=================================== |
65
|
700
|
|
|
700
|
0
|
1237
|
my ( $base, $spec ) = @_; |
66
|
700
|
|
66
|
|
|
1930
|
$spec ||= "+$base"; |
67
|
700
|
50
|
|
|
|
1879
|
return $spec if blessed $spec; |
68
|
|
|
|
|
|
|
|
69
|
700
|
|
|
|
|
998
|
my ( $class, $version ); |
70
|
700
|
50
|
|
|
|
1453
|
if ( ref $spec eq 'ARRAY' ) { |
71
|
0
|
|
|
|
|
0
|
( $class, $version ) = @$spec; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
700
|
|
|
|
|
931
|
$class = $spec; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
700
|
100
|
|
|
|
2063
|
unless ( $class =~ s/\A\+// ) { |
78
|
468
|
|
|
|
|
1430
|
$class = compose_module_name( $base, $class ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
700
|
50
|
|
|
|
20180
|
$version ? use_module( $class, $version ) : use_module($class); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#=================================== |
85
|
|
|
|
|
|
|
sub throw { |
86
|
|
|
|
|
|
|
#=================================== |
87
|
87
|
|
|
87
|
0
|
588
|
my ( $type, $msg, $vars ) = @_; |
88
|
87
|
|
|
|
|
452
|
die Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#=================================== |
92
|
|
|
|
|
|
|
sub new_error { |
93
|
|
|
|
|
|
|
#=================================== |
94
|
29
|
|
|
29
|
0
|
66
|
my ( $type, $msg, $vars ) = @_; |
95
|
29
|
|
|
|
|
85
|
return Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#=================================== |
99
|
|
|
|
|
|
|
sub upgrade_error { |
100
|
|
|
|
|
|
|
#=================================== |
101
|
46
|
|
|
46
|
0
|
93
|
my ( $error, $vars ) = @_; |
102
|
|
|
|
|
|
|
return |
103
|
46
|
50
|
33
|
|
|
479
|
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
|
407
|
my ( $attr, $one, $two ) = @_; |
113
|
200
|
50
|
|
|
|
508
|
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
|
|
|
|
4153
|
return if eval { $two->does($role); }; |
|
200
|
|
|
|
|
539
|
|
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__ |