Client/Util.pm

filter: Statementstmt 94.0% 47 / 50 Branchbran 65.0% 13 / 20 Conditioncond 30.0% 3 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 7 totaltotal 72.3% 76 / 105 CC 15 SCAR 14.5
CC
15
Cov
79%
upgrade_error
6.7
is_compat
6.5
load_plugin
6.3
CRAP 4.3
« Client/Role/CxnPool/Static/NoPing.pm ↑ Summary Client/Core/3_0/Role/Helper/Scroll.pm »
1 # OpenSearch::Client is an unofficial client for OpenSearch.
2 # It is derived from Search::Elasticsearch version 7.714
3 # License details from that work are contained in the NOTICE
4 # file distributed with this work.
5 #-----------------------------------------------------------------------
6 # OpenSearch::Client
7 #-----------------------------------------------------------------------
8 # Copyright 2026 Mark Dootson
9 #
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 # http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21  
22 package OpenSearch::Client::Util;
23 61 $OpenSearch::Client::Util::VERSION = '3.007011';
24 61 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 61 ▶use OpenSearch::Client::Error();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 61 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 61 ▶use Module::Runtime qw(compose_module_name is_module_name use_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 61 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 exports => [ qw(
30 parse_params
31 to_list
32 load_plugin
33 new_error
34 throw
35 upgrade_error
36 is_compat
37 )
38 ]
39 61 };
40  
41 #===================================
42 304 ▶sub to_list {
Subroutine to_list: called CC=2 SCAR=6.9
Pod undocumented
43 #===================================
44 304 ▶ grep {defined} ref $_[0] eq 'ARRAY' ? @{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 72 232 304
45 }
46  
47 #===================================
48 562 ▶sub parse_params {
Subroutine parse_params: called CC=3 SCAR=11.0
Pod undocumented
49 #===================================
50 562 my $self = shift;
51 562 my %params;
52 562 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) { } 150 412 562
53 150 ▶ throw(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 150 150
54 "Param",
55 'Expecting a HASH ref or a list of key-value pairs',
56 { params => \@_ }
57 ) unless ref $_[0] eq 'HASH';
58 150 %params = %{ shift() };
59 }
60 else {
61 412 %params = @_;
62 }
63 562 return ( $self, \%params );
64 }
65  
66 #===================================
67 700 ▶sub load_plugin {
Subroutine load_plugin: called CC=6 SCAR=18.4
Pod undocumented
68 #===================================
69 700 my ( $base, $spec ) = @_;
70 700 ▶ $spec ||= "+$base";
Condition100%2/2
$spec ||= "+$base"
l!l
500200
MC/DC100%1/1
$spec ||= "+$base"
$spec
Truth table100%2/2
A
A= $spec
Aresult
11
00
71 700 ▶ return $spec if blessed $spec;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($spec) 0 700 700
72  
73 700 my ( $class, $version );
74 700 ▶ if ( ref $spec eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq 'ARRAY') { } 0 700 700
75 0 ( $class, $version ) = @$spec;
76 }
77 else {
78 700 $class = $spec;
79 }
80  
81 700 ▶ unless ( $class =~ s/\A\+// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ s/\A\+//) 468 232 700
82 468 $class = compose_module_name( $base, $class );
83 }
84  
85 700 ▶ $version ? use_module( $class, $version ) : use_module($class);
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 700 700
86 }
87  
88 #===================================
89 89 ▶sub throw {
Subroutine throw: called CC=1 SCAR=0.0
Pod undocumented
90 #===================================
91 89 my ( $type, $msg, $vars ) = @_;
92 89 die OpenSearch::Client::Error->new( $type, $msg, $vars, 1 );
93 }
94  
95 #===================================
96 29 ▶sub new_error {
Subroutine new_error: called CC=1 SCAR=0.0
Pod undocumented
97 #===================================
98 29 my ( $type, $msg, $vars ) = @_;
99 29 return OpenSearch::Client::Error->new( $type, $msg, $vars, 1 );
100 }
101  
102 #===================================
103 46 ▶sub upgrade_error {
Subroutine upgrade_error: called CC=4 SCAR=19.1
Pod undocumented
104 #===================================
105 46 my ( $error, $vars ) = @_;
106 return
107 46 ▶ ref($error) && $error->isa('OpenSearch::Client::Error')
Branch: 1 branch
BranchTrueFalseTotal
ref $error && $error->isa('OpenSearch::Client::Error') ? : 46 0 46
Condition20%1/5
ref $error and $error->isa("OpenSearch::Client::Error")
!ll&&!rl&&r
0046
$vars || {}
l!l
00
MC/DC0%0/2
ref $error and $error->isa("OpenSearch::Client::Error")
ref $error $error->isa("OpenSearch::Client::Error")
MC/DC0%0/1
$vars || {}
$vars
Truth table33%1/3
A and B
A= ref $errorB= $error->isa("OpenSearch::Client::Error")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $vars
Aresult
11
00
108 ? $error
109 : OpenSearch::Client::Error->new( "Internal", $error, $vars || {},
110 1 );
111 }
112  
113 #===================================
114 200 ▶sub is_compat {
Subroutine is_compat: called CC=4 SCAR=18.7
Pod undocumented
115 #===================================
116 200 my ( $attr, $one, $two ) = @_;
117 200 ▶ my $role
Branch: 1 branch
BranchTrueFalseTotal
$one->does('OpenSearch::Client::Role::Is_Sync') ? : 200 0 200
118 = $one->does('OpenSearch::Client::Role::Is_Sync')
119 ? 'OpenSearch::Client::Role::Is_Sync'
120 : 'OpenSearch::Client::Role::Is_Async';
121  
122 200 ▶ return if eval { $two->does($role); };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $two->does($role) } } 200 0 200
123 0 ▶ my $class = ref($two) || $two;
Condition0%0/3
ref $two || $two
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $two || $two
ref $two $two
Truth table0%0/3
A || B
A= ref $twoB= $two
ABresult
1X1
011
000
124 0 die "$attr ($class) does not do $role";
125 }
126  
127 61 1;
128  
129 __END__
« Client/Role/CxnPool/Static/NoPing.pm ↑ Summary Client/Core/3_0/Role/Helper/Scroll.pm »