| 1 | package Search::Elasticsearch::Role::API; | ||||||||||||||||||||||||||||
| 2 | 55 | $Search::Elasticsearch::Role::API::VERSION = '6.80'; | |||||||||||||||||||||||||||
| 3 | 55 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 55 | requires 'api_version'; | |||||||||||||||||||||||||||
| 5 | 55 | requires 'api'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 55 | ▶ | use Search::Elasticsearch::Util qw(throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 55 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 55 | our %Handler = ( | |||||||||||||||||||||||||||
| 11 | string => \&_string, | ||||||||||||||||||||||||||||
| 12 | time => \&_string, | ||||||||||||||||||||||||||||
| 13 | date => \&_string, | ||||||||||||||||||||||||||||
| 14 | list => \&_list, | ||||||||||||||||||||||||||||
| 15 | boolean => \&_bool, | ||||||||||||||||||||||||||||
| 16 | enum => \&_list, | ||||||||||||||||||||||||||||
| 17 | number => \&_num, | ||||||||||||||||||||||||||||
| 18 | int => \&_num, | ||||||||||||||||||||||||||||
| 19 | float => \&_num, | ||||||||||||||||||||||||||||
| 20 | double => \&_num, | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #=================================== | ||||||||||||||||||||||||||||
| 24 | sub _bool { | ||||||||||||||||||||||||||||
| 25 | #=================================== | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $val = _detect_bool(@_); | ||||||||||||||||||||||||||
|
Subroutine
_bool: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return ( $val && $val ne 'false' ) ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$val and $val ne "false"
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"
| |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #=================================== | ||||||||||||||||||||||||||||
| 31 | sub _detect_bool { | ||||||||||||||||||||||||||||
| 32 | #=================================== | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $val = shift; | ||||||||||||||||||||||||||
|
Subroutine
_detect_bool: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return '' unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( ref $val eq 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return 'false' if $$val eq 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return 'true' if $$val eq 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | elsif ( UNIVERSAL::isa( $val, "JSON::PP::Boolean" ) ) { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return "$val" ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | return "$val"; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #=================================== | ||||||||||||||||||||||||||||
| 46 | sub _list { | ||||||||||||||||||||||||||||
| 47 | #=================================== | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return join ",", map { _detect_bool($_) } # | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | ref $_[0] eq 'ARRAY' ? @{ $_[0] } : $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_list: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | #=================================== | ||||||||||||||||||||||||||||
| 53 | sub _num { | ||||||||||||||||||||||||||||
| 54 | #=================================== | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return 0 + $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_num: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | #=================================== | ||||||||||||||||||||||||||||
| 59 | sub _string { | ||||||||||||||||||||||||||||
| 60 | #=================================== | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return "$_[0]"; | ||||||||||||||||||||||||||
|
Subroutine
_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | #=================================== | ||||||||||||||||||||||||||||
| 65 | sub _qs_init { | ||||||||||||||||||||||||||||
| 66 | #=================================== | ||||||||||||||||||||||||||||
| 67 | 55 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_qs_init: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 68 | 55 | my $API = shift; | |||||||||||||||||||||||||||
| 69 | 55 | for my $spec ( keys %$API ) { | |||||||||||||||||||||||||||
| 70 | 14190 | my $qs = $API->{$spec}{qs}; | |||||||||||||||||||||||||||
| 71 | 14190 | for my $param ( keys %$qs ) { | |||||||||||||||||||||||||||
| 72 | my $handler = $Handler{ $qs->{$param} } | ||||||||||||||||||||||||||||
| 73 | or throw( "Internal", | ||||||||||||||||||||||||||||
| 74 | "Unknown type <" | ||||||||||||||||||||||||||||
| 75 | 90475 | ▶ | . $qs->{$param} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | . "> for param <$param> in API <$spec>" ); | ||||||||||||||||||||||||||||
| 77 | 90475 | $qs->{$param} = $handler; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 55 | 1; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # ABSTRACT: Provides common functionality for API implementations | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||