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   9430 use Moose::Role;
  17         85  
  17         116  
3 17     17   86837 use Net::Amazon::Signature::V4;
  17         197795  
  17         798  
4             #requires 'region';
5             requires 'service';
6 17     17   204 use POSIX qw(strftime);
  17         33  
  17         132  
7              
8             sub BUILD {
9 572     572 0 716870 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         16530 $self->endpoint;
21 572         15081 $self->_region_for_signature;
22             }
23              
24             sub sign {
25 49     49 0 162 my ($self, $request) = @_;
26              
27 49   66     222 $request->header( Date => $request->header('X-Amz-Date') // strftime( '%Y%m%dT%H%M%SZ', gmtime ) );
28 49         2488 $request->header( Host => $self->endpoint_host );
29 49 50       1588 if ($self->session_token) {
30 0         0 $request->header( 'X-Amz-Security-Token' => $self->session_token );
31             }
32              
33 49         1007 my $sig = Net::Amazon::Signature::V4->new( $self->access_key, $self->secret_key, $self->_region_for_signature, $self->service );
34 49         906 $sig->sign( $request );
35             }
36             1;