File Coverage

blib/lib/Paws/Net/FurlCaller.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Paws::Net::FurlCaller;
2             # This caller uses Furl
3 3     3   2391 use Moose;
  3         10  
  3         25  
4             with 'Paws::Net::RetryCallerRole', 'Paws::Net::CallerRole';
5 3     3   28985 use Furl;
  0            
  0            
6              
7             has debug => ( is => 'rw', required => 0, default => sub { 0 } );
8             has ua => (is => 'rw', required => 1, lazy => 1,
9             default => sub {
10             my $ua = Furl->new(
11             timeout => 60,
12             agent => 'AWS Perl SDK ' . $Paws::VERSION,
13             );
14             return $ua;
15             }
16             );
17              
18             sub send_request {
19             my ($self, $service, $call_object) = @_;
20             my $requestObj = $service->prepare_request_for_call($call_object);
21              
22             my $headers = $requestObj->header_hash;
23             # HTTP::Tiny derives the Host header from the URL. It's an error to set it.
24             delete $headers->{Host};
25              
26             my $method = uc $requestObj->method;
27             my $response = $self->ua->request(
28             url => $requestObj->url,
29             headers => [ %$headers ],
30             method => $method,
31             (defined $requestObj->content)?(content => $requestObj->content):(),
32             );
33              
34             return ($response->code, $response->content, { $response->headers->flatten });
35             }
36              
37             sub caller_to_response {
38             my ($self, $service, $call_object, $status, $content, $headers) = @_;
39            
40             if ($status == 500 and defined $headers->{'x-internal-response'}) {
41             return Paws::Exception->new(message => $content, code => 'ConnectionError', request_id => '');
42             } else {
43             return $service->handle_response($call_object, $status, $content, $headers);
44             }
45             }
46             1;