Elasticsearch/Role/Client/Direct.pm

filter: Statementstmt 36.0% 35 / 97 Branchbran 10.5% 4 / 38 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 47.0% 8 / 17 Podpod 0.0% 0 / 1 totaltotal 26.4% 47 / 178 CC 32 SCAR 39.7
CC
32
Cov
26%
_parse_path
152.8
_parse_qs
42.0
_parse_body
30.0
CRAP 53.2
↑ Summary Elasticsearch/Client/7_0/Role/Bulk.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::Client::Direct;
6 55 $Search::Elasticsearch::Role::Client::Direct::VERSION = '7.30_1'; # TRIAL
7  
8 55 $Search::Elasticsearch::Role::Client::Direct::VERSION = '7.301';
9 55 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 55 with 'Search::Elasticsearch::Role::Client';
11 55 ▶use Search::Elasticsearch::Util qw(load_plugin is_compat throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 55 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 ▶use Package::Stash 0.34 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 55 ▶use Any::URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 55 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #===================================
19 sub parse_request {
20 #===================================
21 0 ▶ my $self = shift;
Subroutine parse_request: not called CC=3 SCAR=24.8
Pod undocumented
22 0 ▶ my $defn = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
23 0 ▶ my $params = { ref $_[0] ? %{ shift() } : @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
24  
25 0 my $request;
26 try {
27 $request = {
28 ignore => delete $params->{ignore} || [],
29 method => $defn->{method} || 'GET',
30 serialize => $defn->{serialize} || 'std',
31 path => $self->_parse_path( $defn, $params ),
32 body => $self->_parse_body( $defn->{body}, $params ),
33 0 ▶ qs => $self->_parse_qs( $defn->{qs}, $params ),
Subroutine __ANON__: not called CC=4 SCAR=30.0
Condition0%0/6
delete $params->{'ignore'} || []
l!l
00
$defn->{'method'} || 'GET'
l!l
00
$defn->{'serialize'} || 'std'
l!l
00
MC/DC0%0/1
delete $params->{'ignore'} || []
delete $params->{'ignore'}
MC/DC0%0/1
$defn->{'method'} || 'GET'
$defn->{'method'}
MC/DC0%0/1
$defn->{'serialize'} || 'std'
$defn->{'serialize'}
Truth table0%0/2
A
A= delete $params->{'ignore'}
Aresult
11
00
Truth table0%0/2
A
A= $defn->{'method'}
Aresult
11
00
Truth table0%0/2
A
A= $defn->{'serialize'}
Aresult
11
00
34 };
35 }
36 catch {
37 0 ▶ chomp $_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
38 0 ▶ my $name = $defn->{name} || '<unknown method>';
Condition0%0/2
$defn->{'name'} || '<unknown method>'
l!l
00
MC/DC0%0/1
$defn->{'name'} || '<unknown method>'
$defn->{'name'}
Truth table0%0/2
A
A= $defn->{'name'}
Aresult
11
00
39 0 $self->logger->throw_error( 'Param', "$_ in ($name) request. " );
40 0 };
41 0 return $request;
42 }
43  
44 #===================================
45 sub _parse_path {
46 #===================================
47 0 ▶ my ( $self, $defn, $params ) = @_;
Subroutine _parse_path: not called CC=13 SCAR=50.3
48 return delete $params->{path}
49 0 ▶ if $params->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"path"} 0 0 0
50 0 my $paths = $defn->{paths};
51 0 my $parts = $defn->{parts};
52  
53 0 my %args;
54 0 keys %$parts;
55 55 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 0 ▶ while ( my ( $key, $req ) = each %$parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$parts) 0 0 0
57 0 my $val = delete $params->{$key};
58 0 ▶ if ( ref $val eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "ARRAY") 0 0 0
59 die "Param ($key) must contain a single value\n"
60 0 ▶ if @$val > 1 and not $req->{multi};
Branch: 1 branch
BranchTrueFalseTotal
if @$val > 1 and not $req->{"multi"} 0 0 0
Condition0%0/3
@$val > 1 and not $req->{"multi"}
!ll&&!rl&&r
000
MC/DC0%0/2
@$val > 1 and not $req->{"multi"}
@$val > 1 not $req->{"multi"}
Truth table0%0/3
A and not(B)
A= @$val > 1B= not $req->{"multi"}
ABresult
0X0
100
111
61 0 $val = join ",", @$val;
62 }
63 0 ▶ if ( !length $val ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $val) 0 0 0
64 die "Missing required param ($key)\n"
65 0 ▶ if $req->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"required"} 0 0 0
66 0 next;
67 }
68 0 utf8::encode($val);
69 0 $args{$key} = uri_escape($val);
70 }
71 0 PATH: for my $path (@$paths) {
72 0 my @keys = keys %{ $path->[0] };
73 0 ▶ next PATH unless @keys == keys %args;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys == keys %args 0 0 0
74 0 for (@keys) {
75 0 ▶ next PATH unless exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$_} 0 0 0
76 }
77 0 my ( $pos, @parts ) = @$path;
78 0 for ( keys %$pos ) {
79 0 $parts[ $pos->{$_} ] = $args{$_};
80 }
81 0 return join "/", '', @parts;
82 }
83  
84 throw(
85 0 'Internal',
86 "Couldn't determine path",
87 { params => $params, defn => $defn }
88 );
89 }
90  
91 #===================================
92 sub _parse_body {
93 #===================================
94 0 ▶ my ( $self, $defn, $params ) = @_;
Subroutine _parse_body: not called CC=5 SCAR=34.0
95 0 ▶ if ( defined $defn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $defn) 0 0 0
96 die("Missing required param (body)\n")
97 0 ▶ if $defn->{required} && !$params->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $defn->{"required"} and not $params->{"body"} 0 0 0
Condition0%0/3
$defn->{"required"} and not $params->{"body"}
!ll&&!rl&&r
000
MC/DC0%0/2
$defn->{"required"} and not $params->{"body"}
$defn->{"required"} not $params->{"body"}
Truth table0%0/3
A and not(B)
A= $defn->{"required"}B= not $params->{"body"}
ABresult
0X0
100
111
98 0 return delete $params->{body};
99 }
100 0 ▶ die("Unknown param (body)\n") if $params->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"body"} 0 0 0
101 0 return undef;
102 }
103  
104 #===================================
105 sub _parse_qs {
106 #===================================
107 0 ▶ my ( $self, $handlers, $params ) = @_;
Subroutine _parse_qs: not called CC=6 SCAR=37.4
108 0 ▶ die "No (qs) defined\n" unless $handlers;
Branch: 1 branch
BranchTrueFalseTotal
unless $handlers 0 0 0
109 0 my %qs;
110  
111 0 ▶ if ( my $raw = delete $params->{params} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $raw = delete $params->{"params"}) 0 0 0
112 0 ▶ die("Arg (params) shoud be a hashref\n")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $raw eq "HASH" 0 0 0
113 unless ref $raw eq 'HASH';
114 0 %qs = %$raw;
115 }
116  
117 0 for my $key ( keys %$params ) {
118 0 ▶ my $handler = $handlers->{$key}
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $handlers->{$key} or die "Unknown param ($key)\n" 0 0 0
119 or die("Unknown param ($key)\n");
120 0 $qs{$key} = $handler->( delete $params->{$key} );
121 }
122 0 return \%qs;
123 }
124  
125 #===================================
126 sub _install_api {
127 #===================================
128 55 ▶ my ( $class, $group ) = @_;
Subroutine _install_api: called CC=5 SCAR=16.4
129 55 my $defns = $class->api;
130 55 my $stash = Package::Stash->new($class);
131  
132 55 ▶ my $group_qr = $group ? qr/$group\./ : qr//;
Branch: 1 branch
BranchTrueFalseTotal
$group ? : 0 55 55
133 55 for my $action ( keys %$defns ) {
134 14905 ▶ my ($name) = ( $action =~ /^$group_qr([^.]+)$/ )
Branch: 1 branch
BranchTrueFalseTotal
my($name) = $action =~ /^$group_qr([^.]+)$/ or next 12925 1980 14905
135 or next;
136 1980 ▶ next if $stash->has_symbol( '&' . $name );
Branch: 1 branch
BranchTrueFalseTotal
if $stash->has_symbol('&' . $name) 0 1980 1980
137  
138 1980 my %defn = ( name => $name, %{ $defns->{$action} } );
139 $stash->add_symbol(
140 '&' . $name => sub {
141 0 ▶ shift->perform_request( \%defn, @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 }
143 1980 );
144 }
145 }
146  
147 #===================================
148 sub _build_namespace {
149 #===================================
150 0 ▶ my ( $self, $ns ) = @_;
Subroutine _build_namespace: not called CC=1 SCAR=6.9
151 0 my $class = load_plugin( $self->_namespace, [$ns] );
152 0 return $class->new(
153 { transport => $self->transport,
154 logger => $self->logger
155 }
156 );
157 }
158  
159 #===================================
160 sub _build_helper {
161 #===================================
162 0 ▶ my ( $self, $name, $sub_class ) = @_;
Subroutine _build_helper: not called CC=1 SCAR=6.9
163 0 my $class = load_plugin( 'Search::Elasticsearch', $sub_class );
164 0 is_compat( $name . '_helper_class', $self->transport, $class );
165 0 return $class;
166 }
167  
168 55 1;
169  
170 # ABSTRACT: Request parsing for Direct clients
171  
172 __END__
↑ Summary Elasticsearch/Client/7_0/Role/Bulk.pm »