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   8601 use Moose::Role;
  17         81  
  17         123  
3 17     17   82448 use Net::Amazon::Signature::V4;
  17         201570  
  17         831  
4             #requires 'region';
5             requires 'service';
6 17     17   280 use POSIX qw(strftime);
  17         45  
  17         162  
7              
8             sub BUILD {
9 573     573 0 710437 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 573         16683 $self->endpoint;
21 573         14847 $self->_region_for_signature;
22             }
23              
24             sub sign {
25 50     50 0 137 my ($self, $request) = @_;
26              
27 50   66     225 $request->header( Date => $request->header('X-Amz-Date') // strftime( '%Y%m%dT%H%M%SZ', gmtime ) );
28 50         2714 $request->header( Host => $self->endpoint_host );
29 50 50       1619 if ($self->session_token) {
30 0         0 $request->header( 'X-Amz-Security-Token' => $self->session_token );
31             }
32              
33 50         1005 my $sig = Net::Amazon::Signature::V4->new( $self->access_key, $self->secret_key, $self->_region_for_signature, $self->service );
34 50         947 $sig->sign( $request );
35             }
36             1;