| 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 | 67 | $Search::Elasticsearch::Util::VERSION = '8.12'; | |||||||||||||||||||||||||||||||||||||
| 20 | 67 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 67 | ▶ | use Search::Elasticsearch::Error(); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 67 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 67 | ▶ | use Module::Runtime qw(compose_module_name is_module_name use_module); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 67 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 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 | }; | |||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 38 | 304 | ▶ | sub to_list { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
to_list: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 39 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 40 | 304 | ▶ | grep {defined} ref $_[0] eq 'ARRAY' ? @{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 44 | 562 | ▶ | sub parse_params { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_params: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 45 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 46 | 562 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 47 | 562 | my %params; | |||||||||||||||||||||||||||||||||||||
| 48 | 562 | ▶ | if ( @_ % 2 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 150 | ▶ | throw( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 50 | "Param", | ||||||||||||||||||||||||||||||||||||||
| 51 | 'Expecting a HASH ref or a list of key-value pairs', | ||||||||||||||||||||||||||||||||||||||
| 52 | { params => \@_ } | ||||||||||||||||||||||||||||||||||||||
| 53 | ) unless ref $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||
| 54 | 150 | %params = %{ shift() }; | |||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||||||||
| 57 | 412 | %params = @_; | |||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||
| 59 | 562 | return ( $self, \%params ); | |||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 63 | 700 | ▶ | sub load_plugin { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
load_plugin: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 64 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 65 | 700 | my ( $base, $spec ) = @_; | |||||||||||||||||||||||||||||||||||||
| 66 | 700 | ▶ | $spec ||= "+$base"; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec ||= "+$base"
MC/DC100%1/1
$spec ||= "+$base"
$spec
Truth table100%2/2
A
A= $spec
| |||||||||||||||||||||||||||||||||||||||
| 67 | 700 | ▶ | return $spec if blessed $spec; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 700 | my ( $class, $version ); | |||||||||||||||||||||||||||||||||||||
| 70 | 700 | ▶ | if ( ref $spec eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ( $class, $version ) = @$spec; | |||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||||||||
| 74 | 700 | $class = $spec; | |||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | 700 | ▶ | unless ( $class =~ s/\A\+// ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 78 | 468 | $class = compose_module_name( $base, $class ); | |||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | 700 | ▶ | $version ? use_module( $class, $version ) : use_module($class); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 85 | 88 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 86 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 87 | 88 | my ( $type, $msg, $vars ) = @_; | |||||||||||||||||||||||||||||||||||||
| 88 | 88 | die Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); | |||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 92 | 29 | ▶ | sub new_error { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 93 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 94 | 29 | my ( $type, $msg, $vars ) = @_; | |||||||||||||||||||||||||||||||||||||
| 95 | 29 | return Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); | |||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 99 | 46 | ▶ | sub upgrade_error { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade_error: called CC=4 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 100 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 101 | 46 | my ( $error, $vars ) = @_; | |||||||||||||||||||||||||||||||||||||
| 102 | return | ||||||||||||||||||||||||||||||||||||||
| 103 | 46 | ▶ | ref($error) && $error->isa('Search::Elasticsearch::Error') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
ref $error and $error->isa("Search::Elasticsearch::Error")
$vars || {}
MC/DC0%0/2
ref $error and $error->isa("Search::Elasticsearch::Error")
ref $error
$error->isa("Search::Elasticsearch::Error")
MC/DC0%0/1
$vars || {}
$vars
Truth table33%1/3
A and B
A= ref $errorB= $error->isa("Search::Elasticsearch::Error")
Truth table0%0/2
A
A= $vars
| |||||||||||||||||||||||||||||||||||||||
| 104 | ? $error | ||||||||||||||||||||||||||||||||||||||
| 105 | : Search::Elasticsearch::Error->new( "Internal", $error, $vars || {}, | ||||||||||||||||||||||||||||||||||||||
| 106 | 1 ); | ||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 110 | 200 | ▶ | sub is_compat { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_compat: called CC=4 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 111 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 112 | 200 | my ( $attr, $one, $two ) = @_; | |||||||||||||||||||||||||||||||||||||
| 113 | 200 | ▶ | my $role | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 114 | = $one->does('Search::Elasticsearch::Role::Is_Sync') | ||||||||||||||||||||||||||||||||||||||
| 115 | ? 'Search::Elasticsearch::Role::Is_Sync' | ||||||||||||||||||||||||||||||||||||||
| 116 | : 'Search::Elasticsearch::Role::Is_Async'; | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | 200 | ▶ | return if eval { $two->does($role); }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my $class = ref($two) || $two; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $two || $two
MC/DC0%0/2
ref $two || $two
ref $two
$two
Truth table0%0/3
A || B
A= ref $twoB= $two
| |||||||||||||||||||||||||||||||||||||||
| 120 | 0 | die "$attr ($class) does not do $role"; | |||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | 67 | 1; | |||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | # ABSTRACT: A utility class for internal use by Search::Elasticsearch | ||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||