blib/lib/Paws/Net/JsonCaller.pm

filter: Statementstmt 95.7% 68 / 71 Branchbran 83.3% 25 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 91.8% 101 / 110 CC 17 SCAR 25.4
CC
17
Cov
92%
_to_jsoncaller_params
17.5
BEGIN
1.0
BEGIN
1.0
CRAP 12.7
« blib/lib/Paws.pm ↑ Summary blib/lib/Paws/Net/QueryCaller.pm »
1 package Paws::Net::JsonCaller;
2 12 ▶ use Paws;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶ use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶ use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 requires 'json_version';
7  
8 12 ▶ use Paws::Net::JsonResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 has response_to_object => (
11 is => 'ro',
12 99 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 99 Paws::Net::JsonResponse->new;
14 }
15 12 );
16  
17 # converts the objects that represent the call into parameters that the API can understand
18 67 ▶ sub _to_jsoncaller_params {
Subroutine _to_jsoncaller_params: called CC=17 SCAR=28.6
19 67 my ($self, $params) = @_;
20  
21 67 ▶ if ($params->does('Paws::API::StrToNativeMapParser')){
Branch: 2 branches
BranchTrueFalseTotal
if ($params->does('Paws::API::StrToNativeMapParser')) { } 2 65 67
elsif ($params->does('Paws::API::StrToObjMapParser')) { } 9 56 65
22 2 return { %{ $params->Map } };
23 } elsif ($params->does('Paws::API::StrToObjMapParser')){
24 9 my $type = $params->meta->get_attribute('Map')->type_constraint;
25 9 ▶ if (my ($inner) = ("$type" =~ m/^HashRef\[ArrayRef\[(.*?)\]/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($inner) = "$type" =~ /^HashRef\[ArrayRef\[(.*?)\]/) { } 1 8 9
26 1 return { map { my $k = $_; ( $k => [ map { $self->_to_jsoncaller_params($_) } @{$params->Map->{$_} } ] ) } keys %{ $params->Map } };
27 } else {
28 8 return { map { $_ => $self->_to_jsoncaller_params($params->Map->{$_}) } keys %{ $params->Map } };
29 }
30 } else {
31 56 my %p;
32 56 foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) {
33 293 ▶ my $key = $params->meta->get_attribute($att)->does('Paws::API::Attribute::Trait::NameInRequest')?$params->meta->get_attribute($att)->request_name:$att;
Branch: 1 branch
BranchTrueFalseTotal
$params->meta->get_attribute($att)->does('Paws::API::Attribute::Trait::NameInRequest') ? : 72 221 293
34 293 ▶ if (defined $params->$att) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->$att) 80 213 293
35 80 my $att_type = $params->meta->get_attribute($att)->type_constraint;
36 80 ▶ if ($att_type eq 'Bool') {
Branch: 8 branches
BranchTrueFalseTotal
if ($att_type eq 'Bool') { } 0 80 80
elsif ($att_type eq 'Int') { } 8 72 80
elsif ($att_type eq 'Str') { } 54 18 72
elsif ('Paws'->is_internal_type($att_type)) { } 0 18 18
elsif ($att_type =~ /^ArrayRef\[(.*)\]/) { } 8 10 18
elsif ($att_type->isa('Moose::Meta::TypeConstraint::Enum')) { } 0 10 10
elsif ($params->$att->does('Paws::API::StrToNativeMapParser')) { } 2 8 10
elsif ($params->$att->does('Paws::API::StrToObjMapParser')) { } 7 1 8
37 0 ▶ $p{ $key } = ($params->$att)?\1:\0;
Branch: 1 branch
BranchTrueFalseTotal
$params->$att ? : 0 0 0
38 } elsif ($att_type eq 'Int') {
39 8 $p{ $key } = int($params->$att);
40 } elsif ($att_type eq 'Str') {
41 # concatenate an empty string so numbers get transmitted as strings
42 54 $p{ $key } = "" . $params->$att;
43 } elsif (Paws->is_internal_type($att_type)) {
44 0 $p{ $key } = $params->$att;
45 } elsif ($att_type =~ m/^ArrayRef\[(.*)\]/) {
46 8 ▶ if (Paws->is_internal_type("$1")){
Branch: 1 branch
BranchTrueFalseTotal
if ('Paws'->is_internal_type("$1")) { } 2 6 8
47 2 $p{ $key } = $params->$att;
48 } else {
49 6 $p{ $key } = [ map { $self->_to_jsoncaller_params($_) } @{ $params->$att } ];
50 }
51 } elsif ($att_type->isa('Moose::Meta::TypeConstraint::Enum')) {
52 0 $p{ $key } = $params->$att;
53 } elsif ($params->$att->does('Paws::API::StrToNativeMapParser')){
54 2 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
55 } elsif ($params->$att->does('Paws::API::StrToObjMapParser')){
56 7 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
57 } else {
58 1 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
59 }
60 }
61 }
62 56 return \%p;
63 }
64 }
65  
66 30 ▶ sub prepare_request_for_call {
Subroutine prepare_request_for_call: called CC=1 SCAR=0.0
Pod undocumented
67 30 my ($self, $call) = @_;
68  
69 30 my $request = Paws::Net::APIRequest->new();
70  
71 30 $request->url($self->_api_endpoint . '/');
72 30 $request->uri('/');
73 30 $request->method('POST');
74  
75 30 my @time = gmtime;
76 30 $request->parameters({ Action => $call->_api_call,
77 Version => $self->version,
78 AWSAccessKeyId => $self->access_key,
79 Timestamp => strftime("%Y-%m-%dT%H:%M:%SZ",@time),
80 });
81 30 $request->header('X-Amz-Target', sprintf('%s.%s', $self->target_prefix, $call->_api_call));
82  
83 30 my $j_version = $self->json_version;
84 30 $request->headers->content_type("application/x-amz-json-$j_version");
85  
86 #$request->header('Content-Encoding', 'amz-1.0');
87 30 $request->header( 'X-Amz-Date' => strftime( '%Y%m%dT%H%M%SZ', @time ) );
88 30 $request->header( Host => $self->endpoint_host );
89  
90 30 my $data = $self->_to_jsoncaller_params($call);
91 30 $request->content(encode_json($data));
92  
93 30 $self->sign($request);
94  
95 30 return $request;
96 }
97 12 1;
« blib/lib/Paws.pm ↑ Summary blib/lib/Paws/Net/QueryCaller.pm »