File Coverage

blib/lib/Paws/Net/JsonCaller.pm
Criterion Covered Total %
statement 57 61 93.4
branch 23 30 76.6
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 85 97 87.6


line stmt bran cond sub pod time code
1             package Paws::Net::JsonCaller;
2 12     12   8775 use Moose::Role;
  12         31  
  12         122  
3 12     12   66416 use JSON::MaybeXS;
  12         32  
  12         921  
4 12     12   88 use POSIX qw(strftime);
  12         32  
  12         111  
5             requires 'json_version';
6              
7             # converts the objects that represent the call into parameters that the API can understand
8             sub _to_jsoncaller_params {
9 36     36   83 my ($self, $params) = @_;
10              
11 36 100       115 if ($params->does('Paws::API::StrToNativeMapParser')){
    100          
12 2         413 return { %{ $params->Map } };
  2         53  
13             } elsif ($params->does('Paws::API::StrToObjMapParser')){
14 9         4491 my $type = $params->meta->get_attribute('Map')->type_constraint;
15 9 100       593 if (my ($inner) = ("$type" =~ m/^HashRef\[ArrayRef\[(.*?)\]/)) {
16 1         39 return { map { my $k = $_; ( $k => [ map { $self->_to_jsoncaller_params($_) } @{$params->Map->{$_} } ] ) } keys %{ $params->Map } };
  1         5  
  1         4  
  1         5  
  1         48  
  1         41  
17             } else {
18 8         263 return { map { $_ => $self->_to_jsoncaller_params($params->Map->{$_}) } keys %{ $params->Map } };
  13         302  
  8         193  
19             }
20             } else {
21 25         11614 my %p;
22 25         98 foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) {
  206         1024  
23 206 50       618 my $key = $params->meta->get_attribute($att)->does('Paws::API::Attribute::Trait::NameInRequest')?$params->meta->get_attribute($att)->request_name:$att;
24 206 100       26950 if (defined $params->$att) {
25 34         114 my $att_type = $params->meta->get_attribute($att)->type_constraint;
26 34 50       2016 if ($att_type eq 'Bool') {
    50          
    100          
    50          
    100          
    50          
    100          
    100          
27 0 0       0 $p{ $key } = ($params->$att)?\1:\0;
28             } elsif ($att_type eq 'Int') {
29 0         0 $p{ $key } = int($params->$att);
30             } elsif ($att_type eq 'Str') {
31             # concatenate an empty string so numbers get transmitted as strings
32 21         2433 $p{ $key } = "" . $params->$att;
33             } elsif ($self->_is_internal_type($att_type)) {
34 0         0 $p{ $key } = $params->$att;
35             } elsif ($att_type =~ m/^ArrayRef\[(.*)\]/) {
36 3 100       600 if ($self->_is_internal_type("$1")){
37 1         33 $p{ $key } = $params->$att;
38             } else {
39 2         9 $p{ $key } = [ map { $self->_to_jsoncaller_params($_) } @{ $params->$att } ];
  5         19  
  2         66  
40             }
41             } elsif ($att_type->isa('Moose::Meta::TypeConstraint::Enum')) {
42 0         0 $p{ $key } = $params->$att;
43             } elsif ($params->$att->does('Paws::API::StrToNativeMapParser')){
44 2         559 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
45             } elsif ($params->$att->does('Paws::API::StrToObjMapParser')){
46 7         1677 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
47             } else {
48 1         251 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
49             }
50             }
51             }
52 25         151 return \%p;
53             }
54             }
55              
56             sub prepare_request_for_call {
57 7     7 0 70 my ($self, $call) = @_;
58              
59 7         66 my $request = Paws::Net::APIRequest->new();
60              
61 7         4813 $request->url($self->_api_endpoint . '/');
62 7         203 $request->uri('/');
63 7         217 $request->method('POST');
64              
65 7         55 my @time = gmtime;
66 7         222 $request->parameters({ Action => $call->_api_call,
67             Version => $self->version,
68             AWSAccessKeyId => $self->access_key,
69             Timestamp => strftime("%Y-%m-%dT%H:%M:%SZ",@time),
70             });
71 7         106 $request->header('X-Amz-Target', sprintf('%s.%s', $self->target_prefix, $call->_api_call));
72              
73 7         279 my $j_version = $self->json_version;
74 7         204 $request->headers->content_type("application/x-amz-json-$j_version");
75              
76             #$request->header('Content-Encoding', 'amz-1.0');
77 7         424 $request->header( 'X-Amz-Date' => strftime( '%Y%m%dT%H%M%SZ', @time ) );
78 7         415 $request->header( Host => $self->endpoint_host );
79              
80 7         278 my $data = $self->_to_jsoncaller_params($call);
81 7         304 $request->content(encode_json($data));
82              
83 7         53 $self->sign($request);
84              
85 7         295 return $request;
86             }
87             1;