File Coverage

blib/lib/Paws/Net/QueryCaller.pm
Criterion Covered Total %
statement 76 76 100.0
branch 25 28 89.2
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 108 114 94.7


line stmt bran cond sub pod time code
1             package Paws::Net::QueryCaller;
2 13     13   213785 use Moose::Role;
  13         40  
  13         138  
3 13     13   84329 use HTTP::Request::Common;
  13         88661  
  13         1155  
4 13     13   119 use POSIX qw(strftime);
  13         34  
  13         142  
5              
6             sub array_flatten_string {
7 18     18 0 30 my $self = shift;
8 18 100       53 return ($self->flattened_arrays)?'%s.%d':'%s.member.%d';
9             }
10              
11             # converts the objects that represent the call into parameters that the API can understand
12             sub _to_querycaller_params {
13 24     24   58 my ($self, $params) = @_;
14 24         39 my %p;
15 24         90 foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) {
  98         888  
16 98 100       311 my $key = $params->meta->get_attribute($att)->does('Paws::API::Attribute::Trait::NameInRequest')?$params->meta->get_attribute($att)->request_name:$att;
17 98 100       13386 if (defined $params->$att) {
18 51         171 my $att_type = $params->meta->get_attribute($att)->type_constraint;
19              
20 51 100       3135 if ($self->_is_internal_type($att_type)) {
    100          
    100          
    100          
    100          
21 33 100       1742 if ($att_type eq 'Bool') {
22 1 50       33 $p{ $key } = ($params->{$att} == 1) ? 'true' : 'false';
23             } else {
24 32         1179 $p{ $key } = $params->{$att};
25             }
26             } elsif ($att_type =~ m/^ArrayRef\[(.*)\]/) {
27 8 100       1765 if ($self->_is_internal_type("$1")){
28 6         17 my $i = 1;
29 6         12 foreach my $value (@{ $params->$att }){
  6         180  
30 8         28 $p{ sprintf($self->array_flatten_string, $key, $i) } = $value;
31 8         29 $i++
32             }
33             } else {
34 2         40 my $i = 1;
35 2         8 foreach my $value (@{ $params->$att }){
  2         56  
36 3         19 my %complex_value = $self->_to_querycaller_params($value);
37 3         10 map { $p{ sprintf($self->array_flatten_string . ".%s", $key, $i, $_) } = $complex_value{$_} } keys %complex_value;
  10         28  
38 3         11 $i++
39             }
40             }
41             } elsif ($params->$att->does('Paws::API::StrToObjMapParser')) {
42 1         270 my $i = 1;
43 1         2 foreach my $map_key (keys %{ $params->$att->Map }){
  1         29  
44 1         9 $p{ "$key.$i.Name" } = $map_key;
45 1         29 my %complex_value = $self->_to_querycaller_params($params->$att->Map->{ $map_key });
46 1         4 map { $p{ "$key.$i.Value.$_" } = $complex_value{$_} } keys %complex_value;
  2         9  
47 1         4 $i++;
48             }
49             } elsif ($params->$att->does('Paws::API::StrToNativeMapParser')) {
50 1         192 my $i = 1;
51 1         4 foreach my $map_key (keys %{ $params->$att->Map }){
  1         29  
52 1         6 $p{ "$key.entry.$i.key" } = $map_key;
53 1         35 $p{ "$key.entry.$i.value" } = $params->$att->Map->{ $map_key };
54 1         4 $i++;
55             }
56             } elsif ($params->$att->does('Paws::API::MapParser')){
57 1         217 my $i = 1;
58 1         25 foreach my $map_key (sort $params->$att->meta->get_attribute_list){
59 18 100       433 next if (not defined $params->$att->$map_key);
60 3         13 $p{ "$key.$i.Name" } = $map_key;
61 3         68 $p{ "$key.$i.Value" } = $params->$att->$map_key;
62 3         10 $i++;
63             }
64             } else {
65 7         1731 my %complex_value = $self->_to_querycaller_params($params->$att);
66 7         15 map { $p{ "$key.$_" } = $complex_value{$_} } keys %complex_value;
  8         41  
67             }
68             }
69             }
70 24         469 return %p;
71             }
72              
73             sub generate_content_from_parameters {
74 13     13 0 35 my ($self, $request) = @_;
75              
76 13         391 $request->headers->content_type('application/x-www-form-urlencoded');
77 13         295 my $url = URI->new('http:');
78 13         1325 $url->query_form($request->parameters);
79 13         2915 my $content = $url->query;
80             # HTML/4.01 says that line breaks are represented as "CR LF" pairs (i.e., `%0D%0A')
81 13 50       175 $content =~ s/(?<!%0D)%0A/%0D%0A/g if (defined $content);
82 13         394 return $content;
83             }
84              
85             sub prepare_request_for_call {
86 13     13 0 135 my ($self, $call) = @_;
87              
88 13         117 my $request = Paws::Net::APIRequest->new();
89              
90 13         8805 $request->url($self->_api_endpoint . '/');
91 13         359 $request->uri('/');
92 13         317 $request->method('POST');
93              
94 13         401 $request->parameters({ Action => $call->_api_call,
95             Version => $self->version,
96             $self->_to_querycaller_params($call)
97             });
98              
99 13 50       91 if (not $self->does('Paws::Net::V2Signature')){
100 13         6718 $request->content($self->generate_content_from_parameters($request));
101             }
102              
103 13         103 $self->sign($request);
104              
105 13         590 return $request;
106             }
107             1;