Elasticsearch/Role/API.pm

filter: Statementstmt 61.1% 22 / 36 Branchbran 5.5% 1 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod n/a totaltotal 39.7% 27 / 68 CC 13 SCAR 30.9
CC
13
Cov
40%
_detect_bool
56.0
_bool
12.0
_list
6.0
CRAP 22.1
« Elasticsearch/TestServer.pm ↑ Summary Elasticsearch/Role/Cxn.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::Role::API;
6 55 $Search::Elasticsearch::Role::API::VERSION = '7.30_1'; # TRIAL
7  
8 55 $Search::Elasticsearch::Role::API::VERSION = '7.301';
9 55 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 55 requires 'api_version';
11 55 requires 'api';
12  
13 55 ▶use Search::Elasticsearch::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 55 our %Handler = (
17 string => \&_string,
18 time => \&_string,
19 date => \&_string,
20 list => \&_list,
21 boolean => \&_bool,
22 enum => \&_list,
23 number => \&_num,
24 int => \&_num,
25 float => \&_num,
26 double => \&_num,
27 );
28  
29 #===================================
30 sub _bool {
31 #===================================
32 0 ▶ my $val = _detect_bool(@_);
Subroutine _bool: not called CC=3 SCAR=24.8
33 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
34 }
35  
36 #===================================
37 sub _detect_bool {
38 #===================================
39 0 ▶ my $val = shift;
Subroutine _detect_bool: not called CC=7 SCAR=40.3
40 0 ▶ return '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
41 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
42 0 ▶ return 'false' if $$val eq 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$val eq 0 0 0 0
43 0 ▶ return 'true' if $$val eq 1;
Branch: 1 branch
BranchTrueFalseTotal
if $$val eq 1 0 0 0
44 }
45 elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) {
46 0 ▶ return "$val" ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
"$val" ? : 0 0 0
47 }
48 0 return "$val";
49 }
50  
51 #===================================
52 sub _list {
53 #===================================
54 0 ▶ return join ",", map { _detect_bool($_) } #
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
55 0 ▶ ref $_[0] eq 'ARRAY' ? @{ $_[0] } : $_[0];
Subroutine _list: not called CC=2 SCAR=17.9
56 }
57  
58 #===================================
59 sub _num {
60 #===================================
61 0 ▶ return 0 + $_[0];
Subroutine _num: not called CC=1 SCAR=6.9
62 }
63  
64 #===================================
65 sub _string {
66 #===================================
67 0 ▶ return "$_[0]";
Subroutine _string: not called CC=1 SCAR=6.9
68 }
69  
70 #===================================
71 sub _qs_init {
72 #===================================
73 55 ▶ my $class = shift;
Subroutine _qs_init: called CC=4 SCAR=13.9
74 55 my $API = shift;
75 55 for my $spec ( keys %$API ) {
76 14905 my $qs = $API->{$spec}{qs};
77 14905 for my $param ( keys %$qs ) {
78 my $handler = $Handler{ $qs->{$param} }
79 or throw( "Internal",
80 "Unknown type <"
81 93225 ▶ . $qs->{$param}
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $Search::Elasticsearch::Role::API::Handler{$qs->{$param}} or throw("Internal", 'Unknown type <' . $qs->{$param} . "> for param <$param> in API <$spec>") 0 93225 93225
82 . "> for param <$param> in API <$spec>" );
83 93225 $qs->{$param} = $handler;
84 }
85 }
86 }
87  
88 55 1;
89  
90 # ABSTRACT: Provides common functionality for API implementations
91  
92 __END__
« Elasticsearch/TestServer.pm ↑ Summary Elasticsearch/Role/Cxn.pm »