lib/App/ElasticSearch/Utilities/HTTPRequest.pm

filter: Statementstmt 50.0% 19 / 38 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 46.5% 27 / 58 CC 7 SCAR 33.5
CC
7
Cov
40%
content
56.0
new
2.0
BEGIN
1.0
CRAP 28.6
« lib/App/ElasticSearch/Utilities/QueryString/FileExpansion.pm ↑ Summary lib/App/ElasticSearch/Utilities/Aggregations.pm »
1 package App::ElasticSearch::Utilities::HTTPRequest;
2 # ABSTRACT: Allow for strange content elements for Elasticsearch APIs
3  
4  
5 14 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 14 our $VERSION = '9.1'; # VERSION
10  
11 14 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Ref::Util qw(is_ref is_arrayref is_hashref);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 14 ▶use parent 'HTTP::Request';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
17 0 my $class = shift;
18 0 my $self = $class->SUPER::new(@_);
19 0 $self->header('Accept' => 'application/json');
20  
21 0 return $self;
22 }
23  
24 0 ▶sub content {
Subroutine content: not called CC=7 SCAR=40.3
Pod documented
25 0 my ($self,$body) = @_;
26  
27 0 ▶ if( is_arrayref($body) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_arrayref($body)) { } 0 0 0
elsif (is_hashref($body)) { } 0 0 0
elsif (is_ref($body)) { } 0 0 0
28 # Bulk does this
29 0 my @body;
30 0 foreach my $entry (@{ $body }) {
31 0 ▶ push @body, ref $entry ? encode_json($entry) : $entry;
Branch: 1 branch
BranchTrueFalseTotal
ref $entry ? : 0 0 0
32 }
33 0 $body = join '', map { "$_\n" } @body;
34 0 $self->header('Content-Type' => 'application/x-ndjson');
35 }
36 elsif( is_hashref($body) ) {
37 0 $self->header('Content-Type' => 'application/json');
38 0 $body = encode_json($body);
39 }
40 elsif( is_ref($body) ) {
41 # We can't handle this
42 0 warn sprintf "Invalid reference type '%s' passed to %s, discarding.", ref($body), __PACKAGE__;
43 0 undef($body);
44 }
45  
46 0 ▶ $self->{_content} = $body if defined $body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $body 0 0 0
47  
48 0 return $self->{_content};
49 }
50  
51 14 1;
52  
53 __END__
« lib/App/ElasticSearch/Utilities/QueryString/FileExpansion.pm ↑ Summary lib/App/ElasticSearch/Utilities/Aggregations.pm »