| 1 | # Licensed to Elasticsearch B.V under one or more agreements. | ||||||||||||||||||||||||||||||||||||||
| 2 | # Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||||||||||||||||||||||||||||||||||||||
| 3 | # See the LICENSE file in the project root for more information | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | package Search::Elasticsearch::Util; | ||||||||||||||||||||||||||||||||||||||
| 6 | 68 | $Search::Elasticsearch::Util::VERSION = '7.30_1'; # TRIAL | |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 68 | $Search::Elasticsearch::Util::VERSION = '7.301'; | |||||||||||||||||||||||||||||||||||||
| 9 | 68 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 68 | ▶ | use Search::Elasticsearch::Error(); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 68 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 68 | ▶ | use Module::Runtime qw(compose_module_name is_module_name use_module); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 68 | use Sub::Exporter -setup => { | |||||||||||||||||||||||||||||||||||||
| 14 | exports => [ qw( | ||||||||||||||||||||||||||||||||||||||
| 15 | parse_params | ||||||||||||||||||||||||||||||||||||||
| 16 | to_list | ||||||||||||||||||||||||||||||||||||||
| 17 | load_plugin | ||||||||||||||||||||||||||||||||||||||
| 18 | new_error | ||||||||||||||||||||||||||||||||||||||
| 19 | throw | ||||||||||||||||||||||||||||||||||||||
| 20 | upgrade_error | ||||||||||||||||||||||||||||||||||||||
| 21 | is_compat | ||||||||||||||||||||||||||||||||||||||
| 22 | ) | ||||||||||||||||||||||||||||||||||||||
| 23 | ] | ||||||||||||||||||||||||||||||||||||||
| 24 | 68 | ▶ | }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 27 | sub to_list { | ||||||||||||||||||||||||||||||||||||||
| 28 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 29 | 304 | ▶ | grep {defined} ref $_[0] eq 'ARRAY' ? @{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
to_list: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 33 | sub parse_params { | ||||||||||||||||||||||||||||||||||||||
| 34 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 35 | 562 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_params: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 36 | 562 | my %params; | |||||||||||||||||||||||||||||||||||||
| 37 | 562 | ▶ | if ( @_ % 2 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 38 | 150 | ▶ | throw( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 39 | "Param", | ||||||||||||||||||||||||||||||||||||||
| 40 | 'Expecting a HASH ref or a list of key-value pairs', | ||||||||||||||||||||||||||||||||||||||
| 41 | { params => \@_ } | ||||||||||||||||||||||||||||||||||||||
| 42 | ) unless ref $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||
| 43 | 150 | %params = %{ shift() }; | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||||||||||||
| 46 | 412 | %params = @_; | |||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||
| 48 | 562 | return ( $self, \%params ); | |||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 52 | sub load_plugin { | ||||||||||||||||||||||||||||||||||||||
| 53 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 54 | 700 | ▶ | my ( $base, $spec ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
load_plugin: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 55 | 700 | ▶ | $spec ||= "+$base"; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec ||= "+$base"
MC/DC100%1/1
$spec ||= "+$base"
$spec
Truth table100%2/2
A
A= $spec
| |||||||||||||||||||||||||||||||||||||||
| 56 | 700 | ▶ | return $spec if blessed $spec; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 700 | my ( $class, $version ); | |||||||||||||||||||||||||||||||||||||
| 59 | 700 | ▶ | if ( ref $spec eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ( $class, $version ) = @$spec; | |||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||||||||||||
| 63 | 700 | $class = $spec; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | 700 | ▶ | unless ( $class =~ s/\A\+// ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 67 | 468 | $class = compose_module_name( $base, $class ); | |||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 700 | ▶ | $version ? use_module( $class, $version ) : use_module($class); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 74 | sub throw { | ||||||||||||||||||||||||||||||||||||||
| 75 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 76 | 87 | ▶ | my ( $type, $msg, $vars ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 77 | 87 | die Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); | |||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 81 | sub new_error { | ||||||||||||||||||||||||||||||||||||||
| 82 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 83 | 29 | ▶ | my ( $type, $msg, $vars ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 84 | 29 | return Search::Elasticsearch::Error->new( $type, $msg, $vars, 1 ); | |||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 88 | sub upgrade_error { | ||||||||||||||||||||||||||||||||||||||
| 89 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 90 | 46 | ▶ | my ( $error, $vars ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade_error: called CC=4 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 91 | return | ||||||||||||||||||||||||||||||||||||||
| 92 | 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
| |||||||||||||||||||||||||||||||||||||||
| 93 | ? $error | ||||||||||||||||||||||||||||||||||||||
| 94 | : Search::Elasticsearch::Error->new( "Internal", $error, $vars || {}, | ||||||||||||||||||||||||||||||||||||||
| 95 | 1 ); | ||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 99 | sub is_compat { | ||||||||||||||||||||||||||||||||||||||
| 100 | #=================================== | ||||||||||||||||||||||||||||||||||||||
| 101 | 200 | ▶ | my ( $attr, $one, $two ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_compat: called CC=4 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 102 | 200 | ▶ | my $role | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 103 | = $one->does('Search::Elasticsearch::Role::Is_Sync') | ||||||||||||||||||||||||||||||||||||||
| 104 | ? 'Search::Elasticsearch::Role::Is_Sync' | ||||||||||||||||||||||||||||||||||||||
| 105 | : 'Search::Elasticsearch::Role::Is_Async'; | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 200 | ▶ | return if eval { $two->does($role); }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 108 | 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
| |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | die "$attr ($class) does not do $role"; | |||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | 68 | 1; | |||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | # ABSTRACT: A utility class for internal use by Search::Elasticsearch | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||||||||||||