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