| 1 | package Paws::Net::RestJsonCaller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use Paws; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use URI::Template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Paws::Net::RestJsonResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | has response_to_object => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 47 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 47 | Paws::Net::RestJsonResponse->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # converts the objects that represent the call into parameters that the API can understand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 58 | ▶ | sub _to_jsoncaller_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_jsoncaller_params: called CC=19 SCAR=34.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 58 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 58 | my %p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 58 | foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 216 | my $attribute = $params->meta->get_attribute($att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 216 | ▶ | next if ($attribute->does('ParamInHeader') or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$attribute->does("ParamInHeader") or $attribute->does("ParamInQuery") or $attribute->does("ParamInURI") or $attribute->does("ParamInBody")
$attribute->does("ParamInHeader") or $attribute->does("ParamInQuery") or $attribute->does("ParamInURI")
$attribute->does("ParamInHeader") or $attribute->does("ParamInQuery")
MC/DC75%3/4
$attribute->does("ParamInHeader") or $attribute->does("ParamInQuery") or $attribute->does("ParamInURI") or $attribute->does("ParamInBody")
$attribute->does("ParamInHeader")
$attribute->does("ParamInQuery")
$attribute->does("ParamInURI")
$attribute->does("ParamInBody")
Truth table80%4/5
A or B or C or D
A= $attribute->does("ParamInHeader")B= $attribute->does("ParamInQuery")C= $attribute->does("ParamInURI")D= $attribute->does("ParamInBody")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $attribute->does('ParamInQuery') or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $attribute->does('ParamInURI') or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | $attribute->does('ParamInBody') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 98 | ▶ | my $key = $attribute->does('Paws::API::Attribute::Trait::NameInRequest')?$attribute->request_name:$att; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 98 | ▶ | if (defined $params->$att) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 39 | my $att_type = $attribute->type_constraint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 39 | ▶ | if ($att_type eq 'Bool') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $p{ $key } = ($params->$att)?\1:\0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } elsif ($att_type eq 'Int') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $p{ $key } = int($params->$att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } elsif ($att_type eq 'Str') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # concatenate an empty string so numbers get transmitted as strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 27 | $p{ $key } = "" . $params->$att; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } elsif (Paws->is_internal_type($att_type)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $p{ $key } = $params->$att; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } elsif ($att_type =~ m/^ArrayRef\[(.*)\]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | if (Paws->is_internal_type("$1")){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | $p{ $key } = $params->$att; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | $p{ $key } = [ map { $self->_to_jsoncaller_params($_) } @{ $params->$att } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } elsif ($att_type->isa('Moose::Meta::TypeConstraint::Enum')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $p{ $key } = $params->$att; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif ($params->$att->does('Paws::API::StrToNativeMapParser')){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | $p{ $key } = { %{ $params->$att->Map } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ($params->$att->does('Paws::API::StrToObjMapParser')){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $type = $params->$att->meta->get_attribute('Map')->type_constraint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (my ($inner) = ("$type" =~ m/^HashRef\[ArrayRef\[(.*?)\]/)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $p{ $key } = { map { my $k = $_; ( $k => [ map { $self->_to_jsoncaller_params($_) } @{$params->$att->Map->{$_} } ] ) } keys %{ $params->$att->Map } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $p{ $key } = { map { $_ => $self->_to_jsoncaller_params($params->$att->Map->{$_}) } keys %{ $params->$att->Map } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | $p{ $key } = $self->_to_jsoncaller_params($params->$att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 58 | return \%p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 58 | ▶ | sub _call_uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_call_uri: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 58 | my ($self, $call) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 58 | my $uri_template = $call->meta->name->_api_uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 58 | my $t = URI::Template->new( $uri_template ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 58 | my $vars = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 58 | foreach my $attribute ($call->meta->get_all_attributes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 228 | my $att_name = $attribute->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 228 | ▶ | if ($attribute->does('Paws::API::Attribute::Trait::ParamInURI')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 84 | $vars->{ $attribute->uri_name } = $call->$att_name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 58 | my $uri = $t->process($vars); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 58 | return $uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 58 | ▶ | sub _to_header_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_header_params: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 58 | my ($self, $request, $call) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 58 | foreach my $attribute ($call->meta->get_all_attributes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 228 | ▶ | if ($attribute->does('Paws::API::Attribute::Trait::ParamInHeader') and $attribute->has_value($call)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$attribute->does("Paws::API::Attribute::Trait::ParamInHeader") and $attribute->has_value($call)
MC/DC100%2/2
$attribute->does("Paws::API::Attribute::Trait::ParamInHeader") and $attribute->has_value($call)
$attribute->does("Paws::API::Attribute::Trait::ParamInHeader")
$attribute->has_value($call)
Truth table100%3/3
A and B
A= $attribute->does("Paws::API::Attribute::Trait::ParamInHeader")B= $attribute->has_value($call)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 18 | $request->headers->header( $attribute->header_name => $attribute->get_value($call) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 58 | ▶ | sub prepare_request_for_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_request_for_call: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 58 | my ($self, $call) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 58 | my $request = Paws::Net::APIRequest->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 58 | my $uri = $self->_call_uri($call); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 58 | my $qparams = { $uri->query_form }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 58 | foreach my $attribute ($call->meta->get_all_attributes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 228 | my $att_name = $attribute->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 228 | ▶ | if ($attribute->does('Paws::API::Attribute::Trait::ParamInQuery')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 43 | ▶ | $qparams->{ $attribute->query_name } = $call->$att_name if (defined $call->$att_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 58 | $uri->query_form(%$qparams); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 58 | $request->uri($uri->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 58 | my $url = $self->_api_endpoint . $uri->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 58 | $request->url($url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 58 | $self->_to_header_params($request, $call); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 58 | ▶ | if ($call->can('_stream_param')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | my $param_name = $call->_stream_param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 9 | ▶ | if (Scalar::Util::blessed($call->$param_name)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | my $attribute = $call->$param_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | my $content = $self->_to_jsoncaller_params($attribute); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | my $att = $call->meta->get_attribute($param_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # if($att->does('Paws::API::Attribute::Trait::NameInRequest')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # $content = { $att->request_name => $content }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | $content = encode_json($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | $request->content($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | $request->headers->header('Content-Type'=>'application/json'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | $request->headers->header('Content-Length'=>length($content)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | $request->content($call->$param_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 49 | my $data = $self->_to_jsoncaller_params($call); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 49 | ▶ | $request->content(encode_json($data)) if (keys %$data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 58 | $request->method($call->_api_method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 58 | $self->sign($request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 58 | return $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||