File Coverage

blib/lib/Paws/Net/S3APIRequest.pm
Criterion Covered Total %
statement 15 19 78.9
branch n/a
condition n/a
subroutine 5 6 83.3
pod n/a
total 20 25 80.0


line stmt bran cond sub pod time code
1             package Paws::Net::S3APIRequest;
2 1     1   14 use Moose;
  1         5  
  1         16  
3             extends 'Paws::Net::APIRequest';
4              
5 1     1   10911 use URI;
  1         40  
  1         44  
6 1     1   23841 use HTTP::Date 'time2isoz';
  1         1987  
  1         132  
7 1     1   755 use MIME::Base64 qw(encode_base64);
  1         762  
  1         59  
8 1     1   8 use Digest::MD5 'md5';
  1         3  
  1         779  
9              
10             has _uri_obj => (is => 'ro', isa => 'URI', lazy => 1, default => sub {
11             return URI->new(shift->url);
12             });
13              
14             #Code taken from https://metacpan.org/source/LEEJO/AWS-S3-0.10/lib/AWS/S3/Signer.pm
15             has 'bucket_name' => (
16             is => 'ro',
17             isa => 'Str',
18             required => 1,
19             lazy => 1,
20             default => sub {
21             my $s = shift;
22              
23             my $endpoint = $s->_uri_obj->host;
24             if ( my ( $name ) = $endpoint =~ m{^(.+?)\.\Q$endpoint\E} ) {
25             return $name;
26             } else {
27             return '';
28             } # end if()
29             }
30             );
31              
32             has 'date' => (
33             is => 'ro',
34             isa => 'Str',
35             default => sub {
36             my $s = shift;
37             my $http_date = time2isoz( time );
38             $http_date =~ s/ /T/g;
39             $http_date =~ s/[\:\-]//g;
40             return $http_date;
41             }
42             );
43              
44             has 'content_type' => (
45             is => 'ro',
46             isa => 'Str',
47             lazy => 1,
48             default => sub {
49             my $s = shift;
50             return '' if $s->method eq 'GET';
51             return '' unless $s->content;
52             return 'text/plain';
53             }
54             );
55              
56             has 'content_md5' => (
57             is => 'ro',
58             isa => 'Str',
59             lazy => 1,
60             default => sub {
61             my $s = shift;
62             return '' unless $s->content;
63             return encode_base64( md5( ${ $s->content } ), '' );
64             }
65             );
66              
67             has 'content_length' => (
68             is => 'ro',
69             isa => 'Int|Undef',
70             lazy => 1,
71             default => sub { length( shift->content || q[] ) }
72             );
73              
74             sub _trim {
75 0     0     my ( $value ) = @_;
76 0           $value =~ s/^\s+//;
77 0           $value =~ s/\s+$//;
78 0           return $value;
79             }
80             1;