Client/Role/API.pm

filter: Statementstmt 54.5% 24 / 44 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.4% 5 / 13 Podpod n/a totaltotal 36.5% 30 / 82 CC 14 SCAR 29.2
CC
14
Cov
37%
_detect_bool
56.0
_bool
12.0
_list
6.0
CRAP 18.5
« Client/Core/3_0/Direct.pm ↑ Summary Client/Core/3_0/Helper/Bulk.pm »
1 # OpenSearch::Client is an unofficial client for OpenSearch.
2 # It is derived from Search::Elasticsearch version 7.714
3 # License details from the original work are contained in the
4 # NOTICE file distributed with this work.
5 #
6 #-----------------------------------------------------------------------
7 # OpenSearch::Client
8 #-----------------------------------------------------------------------
9 # Copyright 2026 Mark Dootson
10 #
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14 #
15 # http://www.apache.org/licenses/LICENSE-2.0
16 #
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22  
23  
24 package OpenSearch::Client::Role::API;
25 56 $OpenSearch::Client::Role::API::VERSION = '3.007011';
26 56 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 56 requires 'api_version';
28 56 requires 'api';
29  
30 56 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 56 ▶use OpenSearch::Client::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 56 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 56 our %Handler = (
35 string => \&_string,
36 time => \&_string,
37 date => \&_string,
38 list => \&_list,
39 boolean => \&_bool,
40 enum => \&_list,
41 number => \&_num,
42 int => \&_num,
43 float => \&_num,
44 double => \&_num,
45 'number|string' => \&_numOrString,
46 'boolean|string' => \&_boolOrString,
47 'boolean|number' => \&_boolOrNumber,
48
49 );
50  
51 #===================================
52 0 ▶sub _bool {
Subroutine _bool: not called CC=3 SCAR=24.8
53 #===================================
54 0 my $val = _detect_bool(@_);
55 0 ▶ return ( $val && $val ne 'false' ) ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$val && $val ne 'false' ? : 0 0 0
Condition0%0/3
$val and $val ne "false"
!ll&&!rl&&r
000
MC/DC0%0/2
$val and $val ne "false"
$val $val ne "false"
Truth table0%0/3
A and B
A= $valB= $val ne "false"
ABresult
0X0
100
111
56 }
57  
58 #===================================
59 0 ▶sub _detect_bool {
Subroutine _detect_bool: not called CC=7 SCAR=40.3
60 #===================================
61 0 my $val = shift;
62 0 ▶ return '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
63 0 ▶ if ( ref $val eq 'SCALAR' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'SCALAR') { } 0 0 0
elsif (UNIVERSAL::isa($val, 'JSON::PP::Boolean')) { } 0 0 0
64 0 ▶ return 'false' if $$val eq 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$val eq 0 0 0 0
65 0 ▶ return 'true' if $$val eq 1;
Branch: 1 branch
BranchTrueFalseTotal
if $$val eq 1 0 0 0
66 }
67 elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) {
68 0 ▶ return "$val" ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
"$val" ? : 0 0 0
69 }
70 0 return "$val";
71 }
72  
73 #===================================
74 0 ▶sub _list {
Subroutine _list: not called CC=2 SCAR=17.9
75 #===================================
76 0 ▶ return join ",", map { _detect_bool($_) } #
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
77 0 ref $_[0] eq 'ARRAY' ? @{ $_[0] } : $_[0];
78 }
79  
80 #===================================
81 0 ▶sub _num {
Subroutine _num: not called CC=1 SCAR=6.9
82 #===================================
83 0 return 0 + $_[0];
84 }
85  
86 #===================================
87 0 ▶sub _string {
Subroutine _string: not called CC=1 SCAR=6.9
88 #===================================
89 0 return "$_[0]";
90 }
91  
92 #===================================
93 0 ▶sub _numOrString {
Subroutine _numOrString: not called CC=2 SCAR=17.9
94 #===================================
95 0 ▶ if (looks_like_number($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($_[0])) 0 0 0
96 0 return _num($_[0]);
97 }
98 0 return _string($_[0]);
99 }
100  
101 #===================================
102 0 ▶sub _boolOrString {
Subroutine _boolOrString: not called CC=1 SCAR=6.9
103 #===================================
104 0 return _detect_bool( @_ );
105 }
106  
107 #===================================
108 0 ▶sub _boolOrNumber {
Subroutine _boolOrNumber: not called CC=1 SCAR=6.9
109 #===================================
110 0 my $val = _detect_bool(@_);
111 0 return _numOrString($val);
112 }
113  
114 #===================================
115 56 ▶sub _qs_init {
Subroutine _qs_init: called CC=4 SCAR=13.9
116 #===================================
117 56 my $class = shift;
118 56 my $API = shift;
119 56 for my $spec ( keys %$API ) {
120 27104 my $qs = $API->{$spec}{qs};
121 27104 for my $param ( keys %$qs ) {
122 my $handler = $Handler{ $qs->{$param} }
123 or throw( "Internal",
124 "Unknown type <"
125 201152 ▶ . $qs->{$param}
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $OpenSearch::Client::Role::API::Handler{$qs->{$param}} or throw("Internal", 'Unknown type <' . $qs->{$param} . "> for param <$param> in API <$spec>") 201152 0 201152
126 . "> for param <$param> in API <$spec>" );
127 201152 $qs->{$param} = $handler;
128 }
129 }
130 }
131  
132 56 1;
133  
134 __END__
« Client/Core/3_0/Direct.pm ↑ Summary Client/Core/3_0/Helper/Bulk.pm »