| 1 | package Net::Amazon::S3::Client::Object; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 99 | $Net::Amazon::S3::Client::Object::VERSION = '0.992'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 99 | ▶ | use Moose 0.85; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 99 | ▶ | use MooseX::StrictConstructor 0.16; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 99 | ▶ | use DateTime::Format::HTTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 99 | ▶ | use Digest::MD5 qw(md5 md5_hex); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 99 | ▶ | use Digest::MD5::File qw(file_md5 file_md5_hex); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 99 | ▶ | use File::stat; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 99 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 99 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 99 | ▶ | use MooseX::Types::DateTime::MoreCoercions 0.07 qw( DateTime ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 99 | ▶ | use IO::File 1.14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 99 | ▶ | use Ref::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # ABSTRACT: An easy-to-use Amazon S3 client object | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 99 | ▶ | use Net::Amazon::S3::Constraint::ACL::Canned; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 99 | ▶ | use Net::Amazon::S3::Constraint::Etag; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 99 | ▶ | use Net::Amazon::S3::Client::Object::Range; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 99 | with 'Net::Amazon::S3::Role::ACL'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 99 | enum 'StorageClass' => | |||||||||||||||||||||||||||||||||||||||||
| 24 | # Current list at https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html#AmazonS3-PutObject-request-header-StorageClass | ||||||||||||||||||||||||||||||||||||||||||
| 25 | [ qw(standard reduced_redundancy standard_ia onezone_ia intelligent_tiering glacier deep_archive) ]; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 99 | has 'client' => | |||||||||||||||||||||||||||||||||||||||||
| 28 | ( is => 'ro', isa => 'Net::Amazon::S3::Client', required => 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 99 | has 'bucket' => | |||||||||||||||||||||||||||||||||||||||||
| 30 | ( is => 'ro', isa => 'Net::Amazon::S3::Client::Bucket', required => 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 99 | has 'key' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 99 | has 'etag' => ( is => 'ro', isa => 'Net::Amazon::S3::Constraint::Etag', required => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 99 | has 'size' => ( is => 'ro', isa => 'Int', required => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | has 'last_modified' => | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | ( is => 'ro', isa => DateTime, coerce => 1, required => 0, default => sub { shift->last_modified_raw }, lazy => 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 99 | has 'last_modified_raw' => | |||||||||||||||||||||||||||||||||||||||||
| 37 | ( is => 'ro', isa => 'Str', required => 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 99 | has 'expires' => ( is => 'rw', isa => DateTime, coerce => 1, required => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 99 | has 'content_type' => ( | |||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | default => 'binary/octet-stream' | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 99 | has 'content_disposition' => ( | |||||||||||||||||||||||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 99 | has 'content_encoding' => ( | |||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 99 | has 'cache_control' => ( | |||||||||||||||||||||||||||||||||||||||||
| 56 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 99 | has 'storage_class' => ( | |||||||||||||||||||||||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | isa => 'StorageClass', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | default => 'standard', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | has 'user_metadata' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 84 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 99 | ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 99 | has 'website_redirect_location' => ( | |||||||||||||||||||||||||||||||||||||||||
| 73 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 99 | has 'encryption' => ( | |||||||||||||||||||||||||||||||||||||||||
| 78 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 99 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | sub range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
range: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my ($self, $range) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return Net::Amazon::S3::Client::Object::Range->new ( | |||||||||||||||||||||||||||||||||||||||||
| 89 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | range => $range, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | ▶ | sub exists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 98 | 'Net::Amazon::S3::Operation::Object::Head', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | return $response->is_success; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | sub _get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 108 | 'Net::Amazon::S3::Operation::Object::Fetch', | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | method => 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | $self->_load_user_metadata ($response->http_response); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | return $self->_get->content; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | sub get_decoded { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_decoded: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | return $self->_get->decoded_content(@_); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | sub get_callback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_callback: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 132 | 'Net::Amazon::S3::Operation::Object::Fetch', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | filename => $callback, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | method => 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return $response->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | sub get_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_filename: called CC=1 SCAR=0.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | my ( $self, $filename ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 144 | 'Net::Amazon::S3::Operation::Object::Fetch', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | method => 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->_load_user_metadata($response->http_response); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | sub _load_user_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_user_metadata: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | my ( $self, $http_response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my %user_metadata; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | for my $header_name ($http_response->header_field_names) { | |||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | ▶ | my ($metadata_name) = lc($header_name) =~ /\A x-amz-meta- (.*) \z/xms | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $user_metadata{$metadata_name} = $http_response->header($header_name); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | %{ $self->user_metadata } = %user_metadata; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 11 | ▶ | sub put { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 11 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | $self->_put( $value, length $value, md5_hex($value) ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 12 | ▶ | sub _put { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_put: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 12 | my ( $self, $value, $size, $md5_hex ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 12 | my $md5_base64 = encode_base64( pack( 'H*', $md5_hex ) ); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 12 | chomp $md5_base64; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 12 | my $conf = { | |||||||||||||||||||||||||||||||||||||||||
| 177 | 'Content-MD5' => $md5_base64, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 'Content-Length' => $size, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 'Content-Type' => $self->content_type, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 12 | ▶ | if ( $self->expires ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | $conf->{Expires} | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | = DateTime::Format::HTTP->format_datetime( $self->expires ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 12 | ▶ | if ( $self->content_encoding ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | $conf->{'Content-Encoding'} = $self->content_encoding; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 12 | ▶ | if ( $self->content_disposition ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | $conf->{'Content-Disposition'} = $self->content_disposition; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 12 | ▶ | if ( $self->cache_control ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | $conf->{'Cache-Control'} = $self->cache_control; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | ▶ | if ( $self->storage_class && $self->storage_class ne 'standard' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->storage_class and $self->storage_class ne "standard"
MC/DC50%1/2
$self->storage_class and $self->storage_class ne "standard"
$self->storage_class
$self->storage_class ne "standard"
Truth table66%2/3
A and B
A= $self->storage_classB= $self->storage_class ne "standard"
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | $conf->{'x-amz-storage-class'} = uc $self->storage_class; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 12 | ▶ | if ( $self->website_redirect_location ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | $conf->{'x-amz-website-redirect-location'} = $self->website_redirect_location; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | $conf->{"x-amz-meta-\L$_"} = $self->user_metadata->{$_} | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 12 | for keys %{ $self->user_metadata }; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 12 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 205 | 'Net::Amazon::S3::Operation::Object::Add', | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | value => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 208 | headers => $conf, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | acl => $self->acl, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | encryption => $self->encryption, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | my $http_response = $response->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | ▶ | confess 'Error uploading ' . $http_response->as_string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | unless $http_response->is_success; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | sub put_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_filename: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my ( $self, $filename ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | my $md5_hex = $self->etag || file_md5_hex($filename); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->etag || file_md5_hex($filename)
MC/DC0%0/2
$self->etag || file_md5_hex($filename)
$self->etag
file_md5_hex($filename)
Truth table33%1/3
A || B
A= $self->etagB= file_md5_hex($filename)
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | my $size = $self->size; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | unless ($size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | my $stat = stat($filename) || confess("No $filename: $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
&Net::Amazon::S3::Client::Object::stat($filename) || confess("No ${filename}: $!")
MC/DC0%0/1
&Net::Amazon::S3::Client::Object::stat($filename) || confess("No ${filename}: $!")
&Net::Amazon::S3::Client::Object::stat($filename)
Truth table50%1/2
A
A= &Net::Amazon::S3::Client::Object::stat($filename)
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $size = $stat->size; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | $self->_put( $self->_content_sub($filename), $size, $md5_hex ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 238 | 'Net::Amazon::S3::Operation::Object::Delete', | ||||||||||||||||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | return $response->is_success; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 10 | ▶ | sub set_acl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_acl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 10 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 248 | 'Net::Amazon::S3::Operation::Object::Acl::Set', | ||||||||||||||||||||||||||||||||||||||||||
| 249 | %params, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 5 | return $response->is_success; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | ▶ | sub add_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_tags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 259 | 'Net::Amazon::S3::Operation::Object::Tags::Add', | ||||||||||||||||||||||||||||||||||||||||||
| 260 | %params, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | return $response->is_success; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 7 | ▶ | sub delete_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_tags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 7 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | my $response = $self->_perform_operation ( | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 'Net::Amazon::S3::Operation::Object::Tags::Delete', | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | (version_id => $params{version_id}) x!! defined $params{version_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | return $response->is_success; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 10 | ▶ | sub initiate_multipart_upload { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initiate_multipart_upload: called CC=8 SCAR=22.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 10 | ▶ | my %args = ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 10 | ▶ | $args{acl} = $args{acl_short} if exists $args{acl_short}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 10 | delete $args{acl_short}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 10 | ▶ | $args{acl} = $self->acl unless $args{acl}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | my $response = $self->_perform_operation ( | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 'Net::Amazon::S3::Operation::Object::Upload::Create', | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | encryption => $self->encryption, | ||||||||||||||||||||||||||||||||||||||||||
| 290 | ($args{acl} ? (acl => $args{acl}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 10 | ▶ | ($args{headers} ? (headers => $args{headers}) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | return unless $response->is_success; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | confess "Couldn't get upload id from initiate_multipart_upload response XML" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | unless $response->upload_id; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return $response->upload_id; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | sub complete_multipart_upload { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete_multipart_upload: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | ▶ | my %args = ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | my $response = $self->_perform_operation ( | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 'Net::Amazon::S3::Operation::Object::Upload::Complete', | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | upload_id => $args{upload_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 311 | etags => $args{etags}, | ||||||||||||||||||||||||||||||||||||||||||
| 312 | part_numbers => $args{part_numbers}, | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return $response->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | sub abort_multipart_upload { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abort_multipart_upload: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | ▶ | my %args = ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | my $response = $self->_perform_operation ( | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 'Net::Amazon::S3::Operation::Object::Upload::Abort', | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | upload_id => $args{upload_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return $response->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | sub put_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_part: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | my %args = ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | #work out content length header | ||||||||||||||||||||||||||||||||||||||||||
| 339 | $args{headers}->{'Content-Length'} = length $args{value} | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | ▶ | if(defined $args{value}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | my $response = $self->_perform_operation ( | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 'Net::Amazon::S3::Operation::Object::Upload::Part', | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | upload_id => $args{upload_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 346 | part_number => $args{part_number}, | ||||||||||||||||||||||||||||||||||||||||||
| 347 | headers => $args{headers}, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | value => $args{value}, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return $response->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub list_parts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_parts: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | confess "Not implemented"; | |||||||||||||||||||||||||||||||||||||||||
| 356 | # TODO - Net::Amazon::S3::Request:ListParts is implemented, but need to | ||||||||||||||||||||||||||||||||||||||||||
| 357 | # define better interface at this level. Currently returns raw XML. | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | sub uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | return Net::Amazon::S3::Operation::Object::Fetch::Request->new ( | |||||||||||||||||||||||||||||||||||||||||
| 363 | s3 => $self->client->s3, | ||||||||||||||||||||||||||||||||||||||||||
| 364 | bucket => $self->bucket, | ||||||||||||||||||||||||||||||||||||||||||
| 365 | key => $self->key, | ||||||||||||||||||||||||||||||||||||||||||
| 366 | method => 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 367 | )->http_request->uri; | ||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | sub query_string_authentication_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_string_authentication_uri: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my ($self, $query_form) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return $self->query_string_authentication_uri_for_method (GET => $query_form); | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | ▶ | sub query_string_authentication_uri_for_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_string_authentication_uri_for_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 4 | my ($self, $method, $query_form) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 4 | return Net::Amazon::S3::Operation::Object::Fetch::Request->new ( | |||||||||||||||||||||||||||||||||||||||||
| 378 | s3 => $self->client->s3, | ||||||||||||||||||||||||||||||||||||||||||
| 379 | bucket => $self->bucket, | ||||||||||||||||||||||||||||||||||||||||||
| 380 | key => $self->key, | ||||||||||||||||||||||||||||||||||||||||||
| 381 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 382 | )->query_string_authentication_uri ($self->expires->epoch, $query_form); | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 5 | ▶ | sub head { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
head: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 5 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||||||||||||||||
| 389 | 'Net::Amazon::S3::Operation::Object::Fetch', | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | key => $self->key, | ||||||||||||||||||||||||||||||||||||||||||
| 392 | method => 'HEAD', | ||||||||||||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | ▶ | return unless $ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | response->is_success; | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | my $http_response = $response->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | my %metadata; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | for my $header_name ($http_response->header_field_names) { | |||||||||||||||||||||||||||||||||||||||||
| 401 | 6 | ▶ | if ($self->_is_metadata_header ($header_name)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 4 | my $metadata_name = $self->_format_metadata_name ($header_name); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 4 | $metadata{$metadata_name} = $http_response->header ($header_name); | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | return \%metadata; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | ▶ | sub _is_metadata_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_metadata_header: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 6 | my (undef, $header) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 6 | $header = lc($header); | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | my %valid_metadata_headers = map +($_ => 1), ( | |||||||||||||||||||||||||||||||||||||||||
| 415 | 'accept-ranges', | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 'cache-control', | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 'etag', | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 'expires', | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 'last-modified', | ||||||||||||||||||||||||||||||||||||||||||
| 420 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 6 | ▶ | return 1 if exists $valid_metadata_headers{$header}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 5 | ▶ | return 1 if $header =~ m/^x-amz-(?!id-2$)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | ▶ | return 1 if $header =~ m/^content-/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 4 | ▶ | sub _format_metadata_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_metadata_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 4 | my (undef, $header) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | $header = lc($header); | |||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | $header =~ s/^x-amz-//; | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | my $metadata_name = join('', map (ucfirst, split(/-/, $header))); | |||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | ▶ | $metadata_name = 'ETag' if ($metadata_name eq 'Etag'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 4 | return $metadata_name; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | sub available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
available: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my %metadata = %{$self->head}; | |||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | # An object is available if: | ||||||||||||||||||||||||||||||||||||||||||
| 445 | # - the storage class isn't GLACIER; | ||||||||||||||||||||||||||||||||||||||||||
| 446 | # - the storage class is GLACIER and the object was fully restored (Restore: ongoing-request="false"); | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | my $glacier = (exists($metadata{StorageClass}) and $metadata{StorageClass} eq 'GLACIER') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $metadata{"StorageClass"} and $metadata{"StorageClass"} eq "GLACIER"
MC/DC0%0/2
exists $metadata{"StorageClass"} and $metadata{"StorageClass"} eq "GLACIER"
exists $metadata{"StorageClass"}
$metadata{"StorageClass"} eq "GLACIER"
Truth table0%0/3
A and B
A= exists $metadata{"StorageClass"}B= $metadata{"StorageClass"} eq "GLACIER"
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | my $restored = (exists($metadata{Restore}) and $metadata{Restore} =~ m/ongoing-request="false"/) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $metadata{"Restore"} and $metadata{"Restore"} =~ /ongoing-request="false"/
MC/DC0%0/2
exists $metadata{"Restore"} and $metadata{"Restore"} =~ /ongoing-request="false"/
exists $metadata{"Restore"}
$metadata{"Restore"} =~ /ongoing-request="false"/
Truth table0%0/3
A and B
A= exists $metadata{"Restore"}B= $metadata{"Restore"} =~ /ongoing-request="false"/
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | return (!$glacier or $restored) ? 1 :0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $glacier or $restored
MC/DC0%0/2
not $glacier or $restored
not $glacier
$restored
Truth table0%0/3
not(A) or B
A= not $glacierB= $restored
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | ▶ | sub restore { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restore: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | my (%conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | my $request = $self->_perform_operation ( | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 'Net::Amazon::S3::Operation::Object::Restore', | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | key => $self->key, | ||||||||||||||||||||||||||||||||||||||||||
| 460 | days => $conf{days}, | ||||||||||||||||||||||||||||||||||||||||||
| 461 | tier => $conf{tier}, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | return $request->http_response; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | ▶ | sub _content_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content_sub: called CC=6 SCAR=29.2
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | my $stat = stat($filename); | |||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | my $remaining = $stat->size; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | my $blksize = $stat->blksize || 4096; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$stat->blksize || 4096
MC/DC0%0/1
$stat->blksize || 4096
$stat->blksize
Truth table50%1/2
A
A= $stat->blksize
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | ▶ | confess "$filename not a readable file with fixed size" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
-r $filename and -f _ || $remaining
-f _ or $remaining
MC/DC0%0/3
-r $filename and -f _ || $remaining
-r $filename
-f _
$remaining
Truth table25%1/4
A and B or C
A= -r $filenameB= -f _C= $remaining
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | unless -r $filename and ( -f _ || $remaining ); | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | ▶ | my $fh = IO::File->new( $filename, 'r' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | or confess "Could not open $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | $fh->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | # upon retries the file is closed and we must reopen it | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | unless ( $fh->opened ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | $fh = IO::File->new( $filename, 'r' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | or confess "Could not open $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $fh->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $remaining = $stat->size; | |||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # warn "read remaining $remaining"; | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | unless ( my $read = $fh->read( $buffer, $blksize ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | # warn "read $read buffer $buffer remaining $remaining"; | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | confess | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$! and $remaining
MC/DC0%0/2
$! and $remaining
$!
$remaining
Truth table0%0/3
A and B
A= $!B= $remaining
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | "Error while reading upload content $filename ($remaining remaining) $!" | ||||||||||||||||||||||||||||||||||||||||||
| 497 | if $! and $remaining; | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | # otherwise, we found EOF | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | $fh->close | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | or confess "close of upload content $filename failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | $buffer ||= '' | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$buffer ||= ""
MC/DC0%0/1
$buffer ||= ""
$buffer
Truth table0%0/2
A
A= $buffer
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | ; # LWP expects an emptry string on finish, read returns 0 | ||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $remaining -= length($buffer); | |||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub _is_multipart_etag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_multipart_etag: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my ( $self, $etag ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | return 1 if($etag =~ /\-\d+$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 78 | ▶ | sub _perform_operation { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_perform_operation: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 78 | my ($self, $operation, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 78 | $self->bucket->_perform_operation ($operation => ( | |||||||||||||||||||||||||||||||||||||||||
| 519 | key => $self->key, | ||||||||||||||||||||||||||||||||||||||||||
| 520 | %params, | ||||||||||||||||||||||||||||||||||||||||||
| 521 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 99 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | __END__ | ||||||||||||||||||||||||||||||||||||||||||