Elasticsearch/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
« Elasticsearch/Role/CxnPool/Static/NoPing.pm ↑ Summary Elasticsearch/Client/8_0/Role/Scroll.pm »
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
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 72 232 304
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
BranchTrueFalseTotal
if (@_ % 2) { } 150 412 562
49 150 ▶ throw(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 150 150
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"
l!l
500200
MC/DC100%1/1
$spec ||= "+$base"
$spec
Truth table100%2/2
A
A= $spec
Aresult
11
00
67 700 ▶ return $spec if blessed $spec;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($spec) 0 700 700
68  
69 700 my ( $class, $version );
70 700 ▶ if ( ref $spec eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq 'ARRAY') { } 0 700 700
71 0 ( $class, $version ) = @$spec;
72 }
73 else {
74 700 $class = $spec;
75 }
76  
77 700 ▶ unless ( $class =~ s/\A\+// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ s/\A\+//) 468 232 700
78 468 $class = compose_module_name( $base, $class );
79 }
80  
81 700 ▶ $version ? use_module( $class, $version ) : use_module($class);
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 700 700
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
BranchTrueFalseTotal
ref $error && $error->isa('Search::Elasticsearch::Error') ? : 46 0 46
Condition20%1/5
ref $error and $error->isa("Search::Elasticsearch::Error")
!ll&&!rl&&r
0046
$vars || {}
l!l
00
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")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $vars
Aresult
11
00
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
BranchTrueFalseTotal
$one->does('Search::Elasticsearch::Role::Is_Sync') ? : 200 0 200
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
BranchTrueFalseTotal
if eval { do { $two->does($role) } } 200 0 200
119 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
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__
« Elasticsearch/Role/CxnPool/Static/NoPing.pm ↑ Summary Elasticsearch/Client/8_0/Role/Scroll.pm »