| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Paws::Net::MojoAsyncCaller; |
|
2
|
2
|
|
|
2
|
|
1754
|
use Moose; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
|
|
with 'Paws::Net::CallerRole'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
18479
|
use Paws::API::Retry; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
82
|
|
|
6
|
2
|
|
|
2
|
|
742
|
use Future; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Future::Mojo; |
|
8
|
|
|
|
|
|
|
use Mojo::UserAgent; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has ua => (is => 'ro', isa => 'Mojo::UserAgent', default => sub { |
|
11
|
|
|
|
|
|
|
Mojo::UserAgent->new->connect_timeout(15)->inactivity_timeout(60); |
|
12
|
|
|
|
|
|
|
}); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub caller_to_response {} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub do_call { |
|
17
|
|
|
|
|
|
|
my ($self, $service, $call_object, $tracker) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$tracker = Paws::API::Retry->new( |
|
20
|
|
|
|
|
|
|
%{ $service->retry }, |
|
21
|
|
|
|
|
|
|
max_tries => $service->max_attempts, |
|
22
|
|
|
|
|
|
|
retry_rules => $service->retriables, |
|
23
|
|
|
|
|
|
|
) if (not defined $tracker); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$tracker->one_more_try; |
|
26
|
|
|
|
|
|
|
my $f = $self->send_request($service, $call_object); |
|
27
|
|
|
|
|
|
|
$f->on_fail(sub { |
|
28
|
|
|
|
|
|
|
my $fail = shift; |
|
29
|
|
|
|
|
|
|
$tracker->operation_result($fail); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ($tracker->should_retry) { |
|
32
|
|
|
|
|
|
|
#my $sleep = Future::Mojo->new_timer(int($tracker->sleep_time)); |
|
33
|
|
|
|
|
|
|
#$sleep->on_done(sub { |
|
34
|
|
|
|
|
|
|
return $self->do_call($service, $call_object, $tracker); |
|
35
|
|
|
|
|
|
|
#}); |
|
36
|
|
|
|
|
|
|
#return $sleep; |
|
37
|
|
|
|
|
|
|
} else { |
|
38
|
|
|
|
|
|
|
Future->fail($fail); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
}); |
|
41
|
|
|
|
|
|
|
return $f; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub send_request { |
|
45
|
|
|
|
|
|
|
my ($self, $service, $call_object) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $requestObj = $service->prepare_request_for_call($call_object); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $headers = $requestObj->header_hash; |
|
50
|
|
|
|
|
|
|
my $method = lc($requestObj->method); |
|
51
|
|
|
|
|
|
|
my $response_class = $call_object->_returns; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $future = Future::Mojo->new; |
|
54
|
|
|
|
|
|
|
$self->ua->$method( |
|
55
|
|
|
|
|
|
|
$requestObj->url => |
|
56
|
|
|
|
|
|
|
$headers => |
|
57
|
|
|
|
|
|
|
($requestObj->content)?$requestObj->content:() => |
|
58
|
|
|
|
|
|
|
sub { |
|
59
|
|
|
|
|
|
|
my ( $ua, $response ) = @_; |
|
60
|
|
|
|
|
|
|
if (my $err = $response->error and not defined $response->error->{ code }){ |
|
61
|
|
|
|
|
|
|
$future->fail(Paws::Exception->new(message => $err->{ message }, code => 'ConnectionError', request_id => '')); |
|
62
|
|
|
|
|
|
|
} else { |
|
63
|
|
|
|
|
|
|
my $res = $service->handle_response($call_object, $response->res->code, $response->res->body, $response->res->headers->to_hash); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if (not ref($res)){ |
|
66
|
|
|
|
|
|
|
$future->done($res); |
|
67
|
|
|
|
|
|
|
} elsif ($res->isa('Paws::Exception')) { |
|
68
|
|
|
|
|
|
|
$future->fail($res); |
|
69
|
|
|
|
|
|
|
} else { |
|
70
|
|
|
|
|
|
|
$future->done($res); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
return $future; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
return $future; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
1; |