File Coverage

blib/lib/Paws/Net/V4Signature.pm
Criterion Covered Total %
statement 18 19 94.7
branch 1 2 50.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 2 0.0
total 26 31 83.8


line stmt bran cond sub pod time code
1             package Paws::Net::V4Signature;
2 17     17   12891 use Moose::Role;
  17         43  
  17         162  
3 17     17   115836 use Net::Amazon::Signature::V4;
  17         249877  
  17         862  
4             #requires 'region';
5             requires 'service';
6 17     17   5488 use POSIX qw(strftime);
  17         57605  
  17         153  
7              
8             sub BUILD {
9 572     572 0 942211 my $self = shift;
10              
11             # These calls are here so that when you construct
12             # the object the endpoint information and the _region_for_signature
13             # are calculated during construction. This is to avoid the fact that
14             # these attributes are lazy (because they depend on other attributes)
15             # and they don't get used until the first method is called, so if
16             # they are incorrect, they don't throw until the first method is called.
17             # It's much better to have them throw when $paws->service('...') is called
18             # as this is the point where the user had specified "incorrect" information,
19             # instead of the problem happening in the first method call.
20 572         19119 $self->endpoint;
21 572         17612 $self->_region_for_signature;
22             }
23              
24             sub sign {
25 49     49 0 160 my ($self, $request) = @_;
26              
27 49   66     254 $request->header( Date => $request->header('X-Amz-Date') // strftime( '%Y%m%dT%H%M%SZ', gmtime ) );
28 49         3158 $request->header( Host => $self->endpoint_host );
29 49 50       1983 if ($self->session_token) {
30 0         0 $request->header( 'X-Amz-Security-Token' => $self->session_token );
31             }
32              
33 49         1100 my $sig = Net::Amazon::Signature::V4->new( $self->access_key, $self->secret_key, $self->_region_for_signature, $self->service );
34 49         991 $sig->sign( $request );
35             }
36             1;