| 1 | package Paws::Net::EC2Caller; | ||||||||||||||
| 2 | 6 | ▶ | use Paws; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 6 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 6 | ▶ | use HTTP::Request::Common; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 6 | ▶ | use POSIX qw(strftime); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 6 | ▶ | use Paws::Net::XMLResponse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | has response_to_object => ( | ||||||||||||||
| 10 | is => 'ro', | ||||||||||||||
| 11 | 84 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 84 | Paws::Net::XMLResponse->new; | |||||||||||||
| 13 | } | ||||||||||||||
| 14 | 6 | ); | |||||||||||||
| 15 | |||||||||||||||
| 16 | 11 | ▶ | sub array_flatten_string { | ||||||||||||
|
Subroutine
array_flatten_string: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||
| 17 | 11 | my $self = shift; | |||||||||||||
| 18 | 11 | ▶ | return ($self->flattened_arrays)?'%s.%d':'%s.member.%d'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | # converts the objects that represent the call into parameters that the API can understand | ||||||||||||||
| 22 | 40 | ▶ | sub _to_querycaller_params { | ||||||||||||
|
Subroutine
_to_querycaller_params: called CC=11 SCAR=24.0
| |||||||||||||||
| 23 | 40 | my ($self, $params) = @_; | |||||||||||||
| 24 | 40 | my %p; | |||||||||||||
| 25 | 40 | foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) { | |||||||||||||
| 26 | 249 | my $key; | |||||||||||||
| 27 | 249 | ▶ | if ($params->meta->get_attribute($att)->does('Paws::API::Attribute::Trait::NameInRequest')){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 223 | $key = $params->meta->get_attribute($att)->request_name; | |||||||||||||
| 29 | } else { | ||||||||||||||
| 30 | 26 | $key = $att; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | |||||||||||||||
| 33 | # This is due to code found in serialize.py (EC2Serializer) | ||||||||||||||
| 34 | 249 | substr($key,0,1) = uc(substr($key,0,1)); | |||||||||||||
| 35 | |||||||||||||||
| 36 | 249 | ▶ | if (defined $params->$att) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 19 | my $att_type = $params->meta->get_attribute($att)->type_constraint; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 19 | ▶ | if (Paws->is_internal_type($att_type)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 40 | 14 | ▶ | if ($att_type eq 'Bool') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 1 | ▶ | $p{ $key } = ($params->{$att} == 1) ? 'true' : 'false'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | } else { | ||||||||||||||
| 43 | 13 | $p{ $key } = $params->{$att}; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | } elsif ($att_type =~ m/^ArrayRef\[(.*)\]/) { | ||||||||||||||
| 46 | 3 | ▶ | if (Paws->is_internal_type("$1")){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | 1 | my $i = 1; | |||||||||||||
| 48 | 1 | foreach my $value (@{ $params->$att }){ | |||||||||||||
| 49 | 2 | $p{ sprintf($self->array_flatten_string, $key, $i) } = $value; | |||||||||||||
| 50 | 2 | $i++ | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | } else { | ||||||||||||||
| 53 | 2 | my $i = 1; | |||||||||||||
| 54 | 2 | foreach my $value (@{ $params->$att }){ | |||||||||||||
| 55 | 4 | my %complex_value = $self->_to_querycaller_params($value); | |||||||||||||
| 56 | 4 | map { $p{ sprintf($self->array_flatten_string . ".%s", $key, $i, $_) } = $complex_value{$_} } keys %complex_value; | |||||||||||||
| 57 | 4 | $i++ | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | } | ||||||||||||||
| 60 | } else { | ||||||||||||||
| 61 | 2 | my %complex_value = $self->_to_querycaller_params($params->$att); | |||||||||||||
| 62 | 2 | map { $p{ "$key.$_" } = $complex_value{$_} } keys %complex_value; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | } | ||||||||||||||
| 65 | } | ||||||||||||||
| 66 | 40 | return %p; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 34 | ▶ | sub generate_content_from_parameters { | ||||||||||||
|
Subroutine
generate_content_from_parameters: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||
| 70 | 34 | my ($self, $request) = @_; | |||||||||||||
| 71 | |||||||||||||||
| 72 | 34 | $request->headers->content_type('application/x-www-form-urlencoded'); | |||||||||||||
| 73 | 34 | my $url = URI->new('http:'); | |||||||||||||
| 74 | 34 | $url->query_form($request->parameters); | |||||||||||||
| 75 | 34 | my $content = $url->query; | |||||||||||||
| 76 | # HTML/4.01 says that line breaks are represented as "CR LF" pairs (i.e., `%0D%0A') | ||||||||||||||
| 77 | 34 | ▶ | $content =~ s/(?<!%0D)%0A/%0D%0A/g if (defined $content); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 34 | return $content; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 34 | ▶ | sub prepare_request_for_call { | ||||||||||||
|
Subroutine
prepare_request_for_call: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 82 | 34 | my ($self, $call) = @_; | |||||||||||||
| 83 | |||||||||||||||
| 84 | 34 | my $request = Paws::Net::APIRequest->new(); | |||||||||||||
| 85 | |||||||||||||||
| 86 | 34 | $request->url($self->_api_endpoint . '/'); | |||||||||||||
| 87 | 34 | $request->uri('/'); | |||||||||||||
| 88 | 34 | $request->method('POST'); | |||||||||||||
| 89 | |||||||||||||||
| 90 | 34 | $request->parameters({ Action => $call->_api_call, | |||||||||||||
| 91 | Version => $self->version, | ||||||||||||||
| 92 | $self->_to_querycaller_params($call) | ||||||||||||||
| 93 | }); | ||||||||||||||
| 94 | |||||||||||||||
| 95 | 34 | $request->content($self->generate_content_from_parameters($request)); | |||||||||||||
| 96 | |||||||||||||||
| 97 | 34 | $self->sign($request); | |||||||||||||
| 98 | |||||||||||||||
| 99 | 34 | return $request; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | 6 | 1; | |||||||||||||