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   6963 use Moose::Role;
  12         29  
  12         98  
3 12     12   62940 use JSON::MaybeXS;
  12         27  
  12         874  
4 12     12   74 use POSIX qw(strftime);
  12         26  
  12         97  
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   71 my ($self, $params) = @_;
10              
11 36 100       98 if ($params->does('Paws::API::StrToNativeMapParser')){
    100          
12 2         330 return { %{ $params->Map } };
  2         47  
13             } elsif ($params->does('Paws::API::StrToObjMapParser')){
14 9         3586 my $type = $params->meta->get_attribute('Map')->type_constraint;
15 9 100       489 if (my ($inner) = ("$type" =~ m/^HashRef\[ArrayRef\[(.*?)\]/)) {
16 1         35 return { map { my $k = $_; ( $k => [ map { $self->_to_jsoncaller_params($_) } @{$params->Map->{$_} } ] ) } keys %{ $params->Map } };
  1         2  
  1         3  
  1         4  
  1         25  
  1         30  
17             } else {
18 8         263 return { map { $_ => $self->_to_jsoncaller_params($params->Map->{$_}) } keys %{ $params->Map } };
  13         311  
  8         186  
19             }
20             } else {
21 25         9749 my %p;
22 25         79 foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) {
  206         895  
23 206 50       499 my $key = $params->meta->get_attribute($att)->does('Paws::API::Attribute::Trait::NameInRequest')?$params->meta->get_attribute($att)->request_name:$att;
24 206 100       22491 if (defined $params->$att) {
25 34         92 my $att_type = $params->meta->get_attribute($att)->type_constraint;
26 34 50       1768 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         2269 $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       525 if ($self->_is_internal_type("$1")){
37 1         24 $p{ $key } = $params->$att;
38             } else {
39 2         5 $p{ $key } = [ map { $self->_to_jsoncaller_params($_) } @{ $params->$att } ];
  5         22  
  2         48  
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         424 $p{ $key } = $self->_to_jsoncaller_params($params->$att);
45             } elsif ($params->$att->does('Paws::API::StrToObjMapParser')){
46 7         1293 $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         137 return \%p;
53             }
54             }
55              
56             sub prepare_request_for_call {
57 7     7 0 73 my ($self, $call) = @_;
58              
59 7         57 my $request = Paws::Net::APIRequest->new();
60              
61 7         4264 $request->url($self->_api_endpoint . '/');
62 7         164 $request->uri('/');
63 7         192 $request->method('POST');
64              
65 7         46 my @time = gmtime;
66 7         183 $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         37 $request->header('X-Amz-Target', sprintf('%s.%s', $self->target_prefix, $call->_api_call));
72              
73 7         230 my $j_version = $self->json_version;
74 7         158 $request->headers->content_type("application/x-amz-json-$j_version");
75              
76             #$request->header('Content-Encoding', 'amz-1.0');
77 7         207 $request->header( 'X-Amz-Date' => strftime( '%Y%m%dT%H%M%SZ', @time ) );
78 7         363 $request->header( Host => $self->endpoint_host );
79              
80 7         207 my $data = $self->_to_jsoncaller_params($call);
81 7         274 $request->content(encode_json($data));
82              
83 7         51 $self->sign($request);
84              
85 7         249 return $request;
86             }
87             1;