line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Paws::Net::RestJsonCaller; |
2
|
7
|
|
|
7
|
|
33397
|
use Moose::Role; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
55
|
|
3
|
7
|
|
|
7
|
|
32114
|
use HTTP::Request::Common; |
|
7
|
|
|
|
|
6891
|
|
|
7
|
|
|
|
|
507
|
|
4
|
7
|
|
|
7
|
|
41
|
use POSIX qw(strftime); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
53
|
|
5
|
7
|
|
|
7
|
|
466
|
use URI::Template; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
173
|
|
6
|
7
|
|
|
7
|
|
38
|
use JSON::MaybeXS; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
5718
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# converts the objects that represent the call into parameters that the API can understand |
9
|
|
|
|
|
|
|
sub _to_jsoncaller_params { |
10
|
4
|
|
|
4
|
|
10
|
my ($self, $params) = @_; |
11
|
4
|
|
|
|
|
7
|
my %p; |
12
|
4
|
|
|
|
|
19
|
foreach my $att (grep { $_ !~ m/^_/ } $params->meta->get_attribute_list) { |
|
25
|
|
|
|
|
138
|
|
13
|
25
|
|
|
|
|
67
|
my $attribute = $params->meta->get_attribute($att); |
14
|
|
|
|
|
|
|
|
15
|
25
|
50
|
33
|
|
|
534
|
next if ($attribute->does('ParamInHeader') or |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
16
|
|
|
|
|
|
|
$attribute->does('ParamInQuery') or |
17
|
|
|
|
|
|
|
$attribute->does('ParamInURI') or |
18
|
|
|
|
|
|
|
$attribute->does('ParamInBody') |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
25
|
50
|
|
|
|
5809
|
my $key = $attribute->does('Paws::API::Attribute::Trait::NameInRequest')?$attribute->request_name:$att; |
22
|
25
|
100
|
|
|
|
2136
|
if (defined $params->$att) { |
23
|
11
|
|
|
|
|
300
|
my $att_type = $attribute->type_constraint; |
24
|
11
|
50
|
|
|
|
93
|
if ($att_type eq 'Bool') { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
0
|
$p{ $key } = ($params->$att)?\1:\0; |
26
|
|
|
|
|
|
|
} elsif ($att_type eq 'Int') { |
27
|
0
|
|
|
|
|
0
|
$p{ $key } = int($params->$att); |
28
|
|
|
|
|
|
|
} elsif ($att_type eq 'Str') { |
29
|
|
|
|
|
|
|
# concatenate an empty string so numbers get transmitted as strings |
30
|
7
|
|
|
|
|
716
|
$p{ $key } = "" . $params->$att; |
31
|
|
|
|
|
|
|
} elsif ($self->_is_internal_type($att_type)) { |
32
|
0
|
|
|
|
|
0
|
$p{ $key } = $params->$att; |
33
|
|
|
|
|
|
|
} elsif ($att_type =~ m/^ArrayRef\[(.*)\]/) { |
34
|
2
|
50
|
|
|
|
333
|
if ($self->_is_internal_type("$1")){ |
35
|
2
|
|
|
|
|
44
|
$p{ $key } = $params->$att; |
36
|
|
|
|
|
|
|
} else { |
37
|
0
|
|
|
|
|
0
|
$p{ $key } = [ map { $self->_to_jsoncaller_params($_) } @{ $params->$att } ]; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} elsif ($att_type->isa('Moose::Meta::TypeConstraint::Enum')) { |
40
|
0
|
|
|
|
|
0
|
$p{ $key } = $params->$att; |
41
|
|
|
|
|
|
|
} elsif ($params->$att->does('Paws::API::StrToNativeMapParser')){ |
42
|
0
|
|
|
|
|
0
|
$p{ $key } = { %{ $params->$att->Map } }; |
|
0
|
|
|
|
|
0
|
|
43
|
|
|
|
|
|
|
} elsif ($params->$att->does('Paws::API::StrToObjMapParser')){ |
44
|
0
|
|
|
|
|
0
|
my $type = $params->$att->meta->get_attribute('Map')->type_constraint; |
45
|
0
|
0
|
|
|
|
0
|
if (my ($inner) = ("$type" =~ m/^HashRef\[ArrayRef\[(.*?)\]/)) { |
46
|
0
|
|
|
|
|
0
|
$p{ $key } = { map { my $k = $_; ( $k => [ map { $self->_to_jsoncaller_params($_) } @{$params->$att->Map->{$_} } ] ) } keys %{ $params->$att->Map } }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
0
|
$p{ $key } = { map { $_ => $self->_to_jsoncaller_params($params->$att->Map->{$_}) } keys %{ $params->$att->Map } }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} else { |
51
|
2
|
|
|
|
|
415
|
$p{ $key } = $self->_to_jsoncaller_params($params->$att); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
4
|
|
|
|
|
20
|
return \%p; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _call_uri { |
59
|
4
|
|
|
4
|
|
12
|
my ($self, $call) = @_; |
60
|
4
|
|
|
|
|
22
|
my $uri_template = $call->meta->name->_api_uri; |
61
|
4
|
|
|
|
|
57
|
my $t = URI::Template->new( $uri_template ); |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
250
|
my $vars = {}; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
12
|
foreach my $attribute ($call->meta->get_all_attributes) { |
66
|
28
|
|
|
|
|
2904
|
my $att_name = $attribute->name; |
67
|
28
|
100
|
|
|
|
58
|
if ($attribute->does('Paws::API::Attribute::Trait::ParamInURI')) { |
68
|
1
|
|
|
|
|
218
|
$vars->{ $attribute->uri_name } = $call->$att_name |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
440
|
my $uri = $t->process($vars); |
73
|
4
|
|
|
|
|
519
|
return $uri; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _to_header_params { |
77
|
4
|
|
|
4
|
|
13
|
my ($self, $request, $call) = @_; |
78
|
4
|
|
|
|
|
15
|
foreach my $attribute ($call->meta->get_all_attributes) { |
79
|
28
|
100
|
66
|
|
|
2668
|
if ($attribute->does('Paws::API::Attribute::Trait::ParamInHeader') and $attribute->has_value($call)) { |
80
|
3
|
|
|
|
|
764
|
$request->headers->header( $attribute->header_name => $attribute->get_value($call) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub prepare_request_for_call { |
86
|
4
|
|
|
4
|
0
|
49
|
my ($self, $call) = @_; |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
41
|
my $request = Paws::Net::APIRequest->new(); |
89
|
|
|
|
|
|
|
|
90
|
4
|
|
|
|
|
2522
|
my $uri = $self->_call_uri($call); |
91
|
|
|
|
|
|
|
|
92
|
4
|
|
|
|
|
26
|
my $qparams = { $uri->query_form }; |
93
|
4
|
|
|
|
|
133
|
foreach my $attribute ($call->meta->get_all_attributes) { |
94
|
28
|
|
|
|
|
2220
|
my $att_name = $attribute->name; |
95
|
28
|
100
|
|
|
|
57
|
if ($attribute->does('Paws::API::Attribute::Trait::ParamInQuery')) { |
96
|
3
|
50
|
|
|
|
666
|
$qparams->{ $attribute->query_name } = $call->$att_name if (defined $call->$att_name); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
4
|
|
|
|
|
402
|
$uri->query_form(%$qparams); |
100
|
|
|
|
|
|
|
|
101
|
4
|
|
|
|
|
215
|
$request->uri($uri->as_string); |
102
|
4
|
|
|
|
|
106
|
my $url = $self->_api_endpoint . $uri->as_string; |
103
|
4
|
|
|
|
|
111
|
$request->url($url); |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
20
|
$self->_to_header_params($request, $call); |
106
|
|
|
|
|
|
|
|
107
|
4
|
100
|
|
|
|
524
|
if ($call->can('_stream_param')) { |
108
|
2
|
|
|
|
|
57
|
my $param_name = $call->_stream_param; |
109
|
2
|
|
|
|
|
50
|
$request->content($call->$param_name); |
110
|
|
|
|
|
|
|
#$request->headers->header( 'content-length' => $request->content_length ); |
111
|
|
|
|
|
|
|
#$request->headers->header( 'content-type' => $self->content_type ); |
112
|
|
|
|
|
|
|
} else { |
113
|
2
|
|
|
|
|
14
|
my $data = $self->_to_jsoncaller_params($call); |
114
|
2
|
|
|
|
|
79
|
$request->content(encode_json($data)); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
4
|
|
|
|
|
102
|
$request->method($call->_api_method); |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
34
|
$self->sign($request); |
120
|
|
|
|
|
|
|
|
121
|
4
|
|
|
|
|
135
|
return $request; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
1; |