Elasticsearch/Util.pm

filter: Statementstmt 94.1% 48 / 51 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.6% 77 / 106 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/7_0/Role/Scroll.pm »
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
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 72 232 304
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
BranchTrueFalseTotal
if (@_ % 2) { } 150 412 562
38 150 ▶ throw(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 150 150
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"
l!l
500200
MC/DC100%1/1
$spec ||= "+$base"
$spec
Truth table100%2/2
A
A= $spec
Aresult
11
00
56 700 ▶ return $spec if blessed $spec;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($spec) 0 700 700
57  
58 700 my ( $class, $version );
59 700 ▶ if ( ref $spec eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq 'ARRAY') { } 0 700 700
60 0 ( $class, $version ) = @$spec;
61 }
62 else {
63 700 $class = $spec;
64 }
65  
66 700 ▶ unless ( $class =~ s/\A\+// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ s/\A\+//) 468 232 700
67 468 $class = compose_module_name( $base, $class );
68 }
69  
70 700 ▶ $version ? use_module( $class, $version ) : use_module($class);
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 700 700
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
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
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
BranchTrueFalseTotal
$one->does('Search::Elasticsearch::Role::Is_Sync') ? : 200 0 200
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
BranchTrueFalseTotal
if eval { do { $two->does($role) } } 200 0 200
108 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
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__
« Elasticsearch/Role/CxnPool/Static/NoPing.pm ↑ Summary Elasticsearch/Client/7_0/Role/Scroll.pm »