| 1 | package Furl::S3; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Class::Accessor::Lite; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Furl::HTTP qw(HEADERS_AS_HASHREF); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Digest::HMAC_SHA1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use HTTP::Date; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use XML::LibXML::XPathContext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Furl::S3::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Params::Validate qw(:types validate_with validate_pos); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use URI::Escape qw(uri_escape_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | Class::Accessor::Lite->mk_accessors(qw(aws_access_key_id aws_secret_access_key secure furl endpoint)); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 21 | 4 | our $DEFAULT_ENDPOINT = 's3.amazonaws.com'; | |||||||||||||||||||||||||||
| 22 | 4 | our $XMLNS = 'http://s3.amazonaws.com/doc/2006-03-01/'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 26 | 3 | validate_with( | |||||||||||||||||||||||||||
| 27 | params => \@_, | ||||||||||||||||||||||||||||
| 28 | spec => { | ||||||||||||||||||||||||||||
| 29 | aws_access_key_id => 1, | ||||||||||||||||||||||||||||
| 30 | aws_secret_access_key => 1, | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | allow_extra => 1, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 35 | 2 | my $aws_access_key_id = delete $args{aws_access_key_id}; | |||||||||||||||||||||||||||
| 36 | 2 | my $aws_secret_access_key = delete $args{aws_secret_access_key}; | |||||||||||||||||||||||||||
| 37 | 2 | ▶ | Carp::croak("aws_access_key_id and aws_secret_access_key are mandatory") unless $aws_access_key_id && $aws_secret_access_key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$aws_access_key_id and $aws_secret_access_key
MC/DC0%0/2
$aws_access_key_id and $aws_secret_access_key
$aws_access_key_id
$aws_secret_access_key
Truth table33%1/3
A and B
A= $aws_access_key_idB= $aws_secret_access_key
| |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | my $secure = delete $args{secure} || '0'; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'secure'} || '0'
MC/DC0%0/1
delete $args{'secure'} || '0'
delete $args{'secure'}
Truth table50%1/2
A
A= delete $args{'secure'}
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | my $endpoint = delete $args{endpoint} || $DEFAULT_ENDPOINT; | ||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'endpoint'} || $Furl::S3::DEFAULT_ENDPOINT
MC/DC0%0/2
delete $args{'endpoint'} || $Furl::S3::DEFAULT_ENDPOINT
delete $args{'endpoint'}
$Furl::S3::DEFAULT_ENDPOINT
Truth table33%1/3
A || B
A= delete $args{'endpoint'}B= $Furl::S3::DEFAULT_ENDPOINT
| |||||||||||||||||||||||||||||
| 40 | 2 | my $furl = Furl::HTTP->new( | |||||||||||||||||||||||||||
| 41 | agent => '$class/'. $VERSION, | ||||||||||||||||||||||||||||
| 42 | %args, | ||||||||||||||||||||||||||||
| 43 | header_format => HEADERS_AS_HASHREF, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | 2 | my $self = bless { | |||||||||||||||||||||||||||
| 46 | endpoint => $endpoint, | ||||||||||||||||||||||||||||
| 47 | secure => $secure, | ||||||||||||||||||||||||||||
| 48 | aws_access_key_id => $aws_access_key_id, | ||||||||||||||||||||||||||||
| 49 | aws_secret_access_key => $aws_secret_access_key, | ||||||||||||||||||||||||||||
| 50 | furl => $furl, | ||||||||||||||||||||||||||||
| 51 | }, $class; | ||||||||||||||||||||||||||||
| 52 | 2 | $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 7 | ▶ | sub _trim { | ||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 7 | my $str = shift; | |||||||||||||||||||||||||||
| 57 | 7 | $str =~ s/^\s+//; | |||||||||||||||||||||||||||
| 58 | 7 | $str =~ s/\s+$//; | |||||||||||||||||||||||||||
| 59 | 7 | $str; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _remove_quote { | ||||||||||||||||||||||||||
|
Subroutine
_remove_quote: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 0 | my $str = shift; | |||||||||||||||||||||||||||
| 64 | 0 | $str =~ s/^"//; | |||||||||||||||||||||||||||
| 65 | 0 | $str =~ s/"$//; | |||||||||||||||||||||||||||
| 66 | 0 | $str; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub _boolean { | ||||||||||||||||||||||||||
|
Subroutine
_boolean: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 70 | 0 | my $str = shift; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( $str eq 'false' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | return 0; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | return 1; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/index.html?BucketRestrictions.html | ||||||||||||||||||||||||||||
| 78 | 7 | ▶ | sub validate_bucket { | ||||||||||||||||||||||||||
|
Subroutine
validate_bucket: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 7 | my $bucket = shift; | |||||||||||||||||||||||||||
| 80 | return | ||||||||||||||||||||||||||||
| 81 | 7 | ▶ | ($bucket =~ qr/^[a-z0-9][a-z0-9\._-]{2,254}$/) && | ||||||||||||||||||||||||||
|
Condition66%2/3
$bucket =~ qr/^[a-z0-9][a-z0-9\._-]{2,254}$/ && !($bucket =~ /^\d+\.\d+\.\d+\.\d+$/)
MC/DC50%1/2
$bucket =~ qr/^[a-z0-9][a-z0-9\._-]{2,254}$/ && !($bucket =~ /^\d+\.\d+\.\d+\.\d+$/)
$bucket =~ qr/^[a-z0-9][a-z0-9\._-]{2,254}$/
!($bucket =~ /^\d+\.\d+\.\d+\.\d+$/)
Truth table66%2/3
A && not(B)
A= $bucket =~ qr/^[a-z0-9][a-z0-9\._-]{2,254}$/B= !($bucket =~ /^\d+\.\d+\.\d+\.\d+$/)
| |||||||||||||||||||||||||||||
| 82 | ($bucket !~ /^\d+\.\d+\.\d+\.\d+$/); # IP Address | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | ▶ | sub is_dns_style { | ||||||||||||||||||||||||||
|
Subroutine
is_dns_style: called CC=8 SCAR=21.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 5 | my $bucket = shift; | |||||||||||||||||||||||||||
| 87 | 5 | ▶ | return unless validate_bucket( $bucket ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 5 | ▶ | return if $bucket =~ /_/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 5 | ▶ | return if length($bucket) < 3 || length($bucket) > 63; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $bucket < 3 or length $bucket > 63
MC/DC0%0/2
length $bucket < 3 or length $bucket > 63
length $bucket < 3
length $bucket > 63
Truth table33%1/3
A or B
A= length $bucket < 3B= length $bucket > 63
| |||||||||||||||||||||||||||||
| 90 | 5 | ▶ | return if $bucket =~ /\.\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 4 | my @parts = split /\./, $bucket; | |||||||||||||||||||||||||||
| 92 | 4 | for my $p(@parts) { | |||||||||||||||||||||||||||
| 93 | 6 | ▶ | return if $p =~ /-$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 2 | return 1; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 4 | ▶ | sub string_to_sign { | ||||||||||||||||||||||||||
|
Subroutine
string_to_sign: called CC=12 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 4 | my( $self, $method, $resource, $headers ) = @_; | |||||||||||||||||||||||||||
| 100 | 4 | ▶ | $headers ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$headers ||= {}
MC/DC0%0/1
$headers ||= {}
$headers
Truth table50%1/2
A
A= $headers
| |||||||||||||||||||||||||||||
| 101 | 4 | my %headers_to_sign; | |||||||||||||||||||||||||||
| 102 | 4 | ▶ | while (my($k, $v) = each %{$headers}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 7 | my $key = lc $k; | |||||||||||||||||||||||||||
| 104 | 7 | ▶ | if ( $key =~ /^(content-md5|content-type|date|expires)$/ or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key =~ /^(content-md5|content-type|date|expires)$/ or $key =~ /^x-amz-/
MC/DC0%0/2
$key =~ /^(content-md5|content-type|date|expires)$/ or $key =~ /^x-amz-/
$key =~ /^(content-md5|content-type|date|expires)$/
$key =~ /^x-amz-/
Truth table66%2/3
A or B
A= $key =~ /^(content-md5|content-type|date|expires)$/B= $key =~ /^x-amz-/
| |||||||||||||||||||||||||||||
| 105 | $key =~ /^x-amz-/ ) { | ||||||||||||||||||||||||||||
| 106 | 7 | $headers_to_sign{$key} = _trim($v); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 4 | my $str = "$method\n"; | |||||||||||||||||||||||||||
| 110 | 4 | ▶ | $str .= $headers_to_sign{'content-md5'} || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$headers_to_sign{'content-md5'} || ''
MC/DC100%1/1
$headers_to_sign{'content-md5'} || ''
$headers_to_sign{'content-md5'}
Truth table100%2/2
A
A= $headers_to_sign{'content-md5'}
| |||||||||||||||||||||||||||||
| 111 | 4 | $str .= "\n"; | |||||||||||||||||||||||||||
| 112 | 4 | ▶ | $str .= $headers_to_sign{'content-type'} || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$headers_to_sign{'content-type'} || ''
MC/DC100%1/1
$headers_to_sign{'content-type'} || ''
$headers_to_sign{'content-type'}
Truth table100%2/2
A
A= $headers_to_sign{'content-type'}
| |||||||||||||||||||||||||||||
| 113 | 4 | $str .= "\n"; | |||||||||||||||||||||||||||
| 114 | 4 | ▶ | $str .= $headers_to_sign{'expires'} || $headers_to_sign{'date'} || ''; | ||||||||||||||||||||||||||
|
Condition60%3/5
$headers_to_sign{'expires'} || $headers_to_sign{'date'} || ''
$headers_to_sign{"expires"} or $headers_to_sign{"date"}
MC/DC0%0/2
$headers_to_sign{'expires'} || $headers_to_sign{'date'} || ''
$headers_to_sign{"expires"}
$headers_to_sign{"date"}
Truth table66%2/3
A or B
A= $headers_to_sign{"expires"}B= $headers_to_sign{"date"}
| |||||||||||||||||||||||||||||
| 115 | 4 | $str .= "\n"; | |||||||||||||||||||||||||||
| 116 | 4 | for my $key( sort grep { /^x-amz-/ } keys %headers_to_sign ) { | |||||||||||||||||||||||||||
| 117 | 1 | $str .= "$key:$headers_to_sign{$key}\n"; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 4 | my( $path, $query ) = split /\?/, $resource; | |||||||||||||||||||||||||||
| 120 | # sub-resource. | ||||||||||||||||||||||||||||
| 121 | 4 | ▶ | if ( $query && $query =~ m{^(acl|policy|location|versions)$} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$query and $query =~ /^(acl|policy|location|versions)$/
MC/DC0%0/2
$query and $query =~ /^(acl|policy|location|versions)$/
$query
$query =~ /^(acl|policy|location|versions)$/
Truth table33%1/3
A and B
A= $queryB= $query =~ /^(acl|policy|location|versions)$/
| |||||||||||||||||||||||||||||
| 122 | 0 | $str .= $resource; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | else { | ||||||||||||||||||||||||||||
| 125 | 4 | $str .= $path; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 4 | $str; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 3 | ▶ | sub sign { | ||||||||||||||||||||||||||
|
Subroutine
sign: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 3 | my( $self, $str ) = @_; | |||||||||||||||||||||||||||
| 133 | 3 | my $hmac = Digest::HMAC_SHA1->new( $self->aws_secret_access_key ); | |||||||||||||||||||||||||||
| 134 | 3 | $hmac->add( $str ); | |||||||||||||||||||||||||||
| 135 | 3 | encode_base64( $hmac->digest, '' ); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1 | ▶ | sub resource { | ||||||||||||||||||||||||||
|
Subroutine
resource: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 1 | my( $self, $bucket, $key, $subresource ) = @_; | |||||||||||||||||||||||||||
| 140 | 1 | my $resource = $bucket; | |||||||||||||||||||||||||||
| 141 | 1 | ▶ | $resource = '/'. $resource unless $resource =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 1 | ▶ | if ( defined $key ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 1 | $key = _normalize_key($key); | |||||||||||||||||||||||||||
| 144 | 1 | $resource = join '/', $resource, $key; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 1 | ▶ | if ( $subresource ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | $resource .= '?'. $subresource; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 1 | $resource =~ s{//}{/}g; | |||||||||||||||||||||||||||
| 150 | 1 | $resource; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 1 | ▶ | sub _path_query { | ||||||||||||||||||||||||||
|
Subroutine
_path_query: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 154 | 1 | my( $self, $path, $q ) = @_; | |||||||||||||||||||||||||||
| 155 | 1 | ▶ | $path = '/'. $path unless $path =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | my $qs = ref($q) eq 'HASH' ? | ||||||||||||||||||||||||||||
| 157 | 1 | ▶ | join('&', map { $_. '='. uri_escape_utf8( $q->{$_} ) } keys %{$q}) : $q; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 1 | ▶ | $path .= '?'. $qs if $qs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 1 | $path; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub host_and_path_query { | ||||||||||||||||||||||||||
|
Subroutine
host_and_path_query: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 1 | my( $self, $bucket, $key, $params ) = @_; | |||||||||||||||||||||||||||
| 164 | 1 | my($host, $path_query); | |||||||||||||||||||||||||||
| 165 | 1 | $key = _normalize_key($key); | |||||||||||||||||||||||||||
| 166 | 1 | ▶ | if ( is_dns_style($bucket) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 1 | $host = join '.', $bucket, $self->endpoint; | |||||||||||||||||||||||||||
| 168 | 1 | $path_query = $self->_path_query( $key, $params ); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | else { | ||||||||||||||||||||||||||||
| 171 | 0 | $host = $self->endpoint; | |||||||||||||||||||||||||||
| 172 | 0 | $path_query = $self->_path_query( join('/', $bucket, $key), $params ); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 1 | $path_query =~ s{//}{/}g; | |||||||||||||||||||||||||||
| 175 | 1 | return ($host, $path_query); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 180 | 0 | my( $method, $bucket, $key, $params, $headers, $furl_options ) = @_; | |||||||||||||||||||||||||||
| 181 | 0 | validate_pos( @_, 1, 1, | |||||||||||||||||||||||||||
| 182 | { type => SCALAR | UNDEF, optional => 1 }, | ||||||||||||||||||||||||||||
| 183 | { type => HASHREF | UNDEF | SCALAR , optional => 1, }, | ||||||||||||||||||||||||||||
| 184 | { type => HASHREF | UNDEF , optional => 1, }, | ||||||||||||||||||||||||||||
| 185 | { type => HASHREF | UNDEF , optional => 1, }, ); | ||||||||||||||||||||||||||||
| 186 | 0 | $self->clear_error; | |||||||||||||||||||||||||||
| 187 | 0 | ▶ | $key ||= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$key ||= ""
MC/DC0%0/1
$key ||= ""
$key
Truth table0%0/2
A
A= $key
| |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $params ||= +{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
| |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $headers ||= +{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$headers ||= {}
MC/DC0%0/1
$headers ||= {}
$headers
Truth table0%0/2
A
A= $headers
| |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $furl_options ||= +{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$furl_options ||= {}
MC/DC0%0/1
$furl_options ||= {}
$furl_options
Truth table0%0/2
A
A= $furl_options
| |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | my %h; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | while (my($key, $val) = each %{$headers}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | $key =~ s/_/-/g; # content_type => content-type | |||||||||||||||||||||||||||
| 195 | 0 | $h{lc($key)} = $val | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ( !$h{'expires'} && !$h{'date'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$h{"expires"} or $h{"date"}
MC/DC0%0/2
$h{"expires"} or $h{"date"}
$h{"expires"}
$h{"date"}
Truth table0%0/3
A or B
A= $h{"expires"}B= $h{"date"}
| |||||||||||||||||||||||||||||
| 198 | 0 | $h{'date'} = time2str(time); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 0 | my $resource = $self->resource( $bucket, $key ); | |||||||||||||||||||||||||||
| 201 | 0 | my $string_to_sign = | |||||||||||||||||||||||||||
| 202 | $self->string_to_sign( $method, $resource, \%h ); | ||||||||||||||||||||||||||||
| 203 | 0 | my $signed_string = $self->sign( $string_to_sign ); | |||||||||||||||||||||||||||
| 204 | 0 | my $auth_header = 'AWS '. $self->aws_access_key_id. ':'. $signed_string; | |||||||||||||||||||||||||||
| 205 | 0 | $h{'authorization'} = $auth_header; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | my( $host, $path_query ) = | |||||||||||||||||||||||||||
| 208 | $self->host_and_path_query( $bucket, $key, $params ); | ||||||||||||||||||||||||||||
| 209 | 0 | my %res; | |||||||||||||||||||||||||||
| 210 | 0 | my @h = %h; | |||||||||||||||||||||||||||
| 211 | @res{qw(ver code msg headers body)} = $self->furl->request( | ||||||||||||||||||||||||||||
| 212 | method => $method, | ||||||||||||||||||||||||||||
| 213 | scheme => ($self->secure ? 'https' : 'http'), | ||||||||||||||||||||||||||||
| 214 | host => $host, | ||||||||||||||||||||||||||||
| 215 | path_query => $path_query, | ||||||||||||||||||||||||||||
| 216 | headers => \@h, | ||||||||||||||||||||||||||||
| 217 | 0 | ▶ | %{$furl_options}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||
| 219 | 0 | return \%res; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 1 | ▶ | sub signed_url { | ||||||||||||||||||||||||||
|
Subroutine
signed_url: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 223 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 224 | 1 | validate_pos(@_, 1, 1, +{ regexp => qr/^\d+$/, }); | |||||||||||||||||||||||||||
| 225 | 1 | my( $bucket, $key, $expires ) = @_; | |||||||||||||||||||||||||||
| 226 | 1 | my $resource = $self->resource( $bucket, $key ); | |||||||||||||||||||||||||||
| 227 | 1 | my $string_to_sign = $self->string_to_sign('GET', $resource, +{ | |||||||||||||||||||||||||||
| 228 | expires => $expires, | ||||||||||||||||||||||||||||
| 229 | }); | ||||||||||||||||||||||||||||
| 230 | 1 | my $sig = $self->sign( $string_to_sign ); | |||||||||||||||||||||||||||
| 231 | 1 | my($host, $path_query) = $self->host_and_path_query( $bucket, $key, +{ | |||||||||||||||||||||||||||
| 232 | AWSAccessKeyId => $self->aws_access_key_id, | ||||||||||||||||||||||||||||
| 233 | Expires => $expires, | ||||||||||||||||||||||||||||
| 234 | Signature => $sig, | ||||||||||||||||||||||||||||
| 235 | } ); | ||||||||||||||||||||||||||||
| 236 | 1 | ▶ | sprintf '%s://%s%s', ($self->secure ? 'https' : 'http'), $host, $path_query; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub _create_xpc { | ||||||||||||||||||||||||||
|
Subroutine
_create_xpc: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 241 | 0 | my( $self, $string ) = @_; | |||||||||||||||||||||||||||
| 242 | 0 | my $xml = XML::LibXML->new; | |||||||||||||||||||||||||||
| 243 | 0 | my $doc = $xml->parse_string( $string ); | |||||||||||||||||||||||||||
| 244 | 0 | my $xpc = XML::LibXML::XPathContext->new( $doc ); | |||||||||||||||||||||||||||
| 245 | 0 | $xpc->registerNs('s3' => $XMLNS); | |||||||||||||||||||||||||||
| 246 | 0 | return $xpc; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub list_buckets { | ||||||||||||||||||||||||||
|
Subroutine
list_buckets: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 251 | 0 | my $res = $self->request( 'GET', '/' ); | |||||||||||||||||||||||||||
| 252 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | 0 | my $xpc = $self->_create_xpc( $res->{body} ); | |||||||||||||||||||||||||||
| 256 | 0 | my @buckets; | |||||||||||||||||||||||||||
| 257 | 0 | for my $node($xpc->findnodes('/s3:ListAllMyBucketsResult/s3:Buckets/s3:Bucket')) { | |||||||||||||||||||||||||||
| 258 | 0 | my $name = $xpc->findvalue('./s3:Name', $node); | |||||||||||||||||||||||||||
| 259 | 0 | my $creation_date = $xpc->findvalue('./s3:CreationDate', $node); | |||||||||||||||||||||||||||
| 260 | 0 | push @buckets, +{ | |||||||||||||||||||||||||||
| 261 | name => $name, | ||||||||||||||||||||||||||||
| 262 | creation_date => $creation_date, | ||||||||||||||||||||||||||||
| 263 | }; | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | return +{ | ||||||||||||||||||||||||||||
| 266 | 0 | buckets => \@buckets, | |||||||||||||||||||||||||||
| 267 | owner => +{ | ||||||||||||||||||||||||||||
| 268 | id => $xpc->findvalue('/s3:ListAllMyBucketsResult/s3:Owner/s3:ID'), | ||||||||||||||||||||||||||||
| 269 | display_name => $xpc->findvalue('/s3:ListAllMyBucketsResult/s3:Owner/s3:DisplayName'), | ||||||||||||||||||||||||||||
| 270 | }, | ||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 1 | ▶ | sub create_bucket { | ||||||||||||||||||||||||||
|
Subroutine
create_bucket: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 275 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 276 | 1 | my( $bucket, $headers ) = @_; | |||||||||||||||||||||||||||
| 277 | 1 | validate_pos( @_, | |||||||||||||||||||||||||||
| 278 | { type => SCALAR, | ||||||||||||||||||||||||||||
| 279 | callbacks => { bucket_name => \&validate_bucket } }, | ||||||||||||||||||||||||||||
| 280 | { type => HASHREF, optional => 1, } ); | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | my $res = $self->request( 'PUT', $bucket, undef, undef, $headers ); | |||||||||||||||||||||||||||
| 283 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | 0 | return 1; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 2 | ▶ | sub delete_bucket { | ||||||||||||||||||||||||||
|
Subroutine
delete_bucket: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 291 | 2 | my( $bucket ) = @_; | |||||||||||||||||||||||||||
| 292 | 2 | validate_pos( @_, 1 ); | |||||||||||||||||||||||||||
| 293 | 0 | my $res = $self->request( 'DELETE', $bucket ); | |||||||||||||||||||||||||||
| 294 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 0 | return 1; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub list_objects { | ||||||||||||||||||||||||||
|
Subroutine
list_objects: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 301 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 302 | 0 | my( $bucket, $params ) = @_; | |||||||||||||||||||||||||||
| 303 | 0 | validate_pos( @_, 1, { type => HASHREF, optional => 1 }); | |||||||||||||||||||||||||||
| 304 | 0 | my $res = $self->request( 'GET', $bucket, undef, $params ); | |||||||||||||||||||||||||||
| 305 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | 0 | my $xpc = $self->_create_xpc( $res->{body} ); | |||||||||||||||||||||||||||
| 309 | 0 | my @contents; | |||||||||||||||||||||||||||
| 310 | 0 | for my $node($xpc->findnodes('/s3:ListBucketResult/s3:Contents')) { | |||||||||||||||||||||||||||
| 311 | 0 | push @contents, +{ | |||||||||||||||||||||||||||
| 312 | key => $xpc->findvalue('./s3:Key', $node), | ||||||||||||||||||||||||||||
| 313 | etag => _remove_quote( $xpc->findvalue('./s3:ETag', $node) ), | ||||||||||||||||||||||||||||
| 314 | storage_class => $xpc->findvalue('./s3:StorageClass', $node), | ||||||||||||||||||||||||||||
| 315 | last_modified => $xpc->findvalue('./s3:LastModified', $node), | ||||||||||||||||||||||||||||
| 316 | size => $xpc->findvalue('./s3:Size', $node), | ||||||||||||||||||||||||||||
| 317 | owner => +{ | ||||||||||||||||||||||||||||
| 318 | id => $xpc->findvalue('./s3:Owner/s3:ID', $node), | ||||||||||||||||||||||||||||
| 319 | display_name => $xpc->findvalue('./s3:Owner/s3:DisplayName', $node), | ||||||||||||||||||||||||||||
| 320 | }, | ||||||||||||||||||||||||||||
| 321 | }; | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | 0 | my @common_prefixes; | |||||||||||||||||||||||||||
| 324 | 0 | for my $node($xpc->findnodes('/s3:ListBucketResult/s3:CommonPrefixes')) { | |||||||||||||||||||||||||||
| 325 | 0 | push @common_prefixes, +{ | |||||||||||||||||||||||||||
| 326 | prefix => $xpc->findvalue('./s3:Prefix', $node), | ||||||||||||||||||||||||||||
| 327 | }; | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | return +{ | ||||||||||||||||||||||||||||
| 330 | 0 | name => $xpc->findvalue('/s3:ListBucketResult/s3:Name'), | |||||||||||||||||||||||||||
| 331 | is_truncated => _boolean($xpc->findvalue('/s3:ListBucketResult/s3:IsTruncated')), | ||||||||||||||||||||||||||||
| 332 | delimiter => $xpc->findvalue('/s3:ListBucketResult/s3:Delimiter'), | ||||||||||||||||||||||||||||
| 333 | max_keys => $xpc->findvalue('/s3:ListBucketResult/s3:MaxKeys'), | ||||||||||||||||||||||||||||
| 334 | marker => $xpc->findvalue('/s3:ListBucketResult/s3:Marker'), | ||||||||||||||||||||||||||||
| 335 | contents => \@contents, | ||||||||||||||||||||||||||||
| 336 | common_prefixes => \@common_prefixes, | ||||||||||||||||||||||||||||
| 337 | }; | ||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 1 | ▶ | sub create_object { | ||||||||||||||||||||||||||
|
Subroutine
create_object: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 341 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 342 | 1 | my( $bucket, $key, $content, $headers ) = @_; | |||||||||||||||||||||||||||
| 343 | 1 | validate_pos( @_, 1, 1, | |||||||||||||||||||||||||||
| 344 | { type => HANDLE | SCALAR }, | ||||||||||||||||||||||||||||
| 345 | { type => HASHREF, optional => 1 } ); | ||||||||||||||||||||||||||||
| 346 | 0 | my $res = $self->request( 'PUT', $bucket, $key, undef, $headers, +{ content => $content }); | |||||||||||||||||||||||||||
| 347 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | 0 | return 1; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | sub create_object_from_file { | ||||||||||||||||||||||||||
|
Subroutine
create_object_from_file: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 354 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 355 | 0 | my( $bucket, $key, $filename, $headers ) = @_; | |||||||||||||||||||||||||||
| 356 | 0 | validate_pos( @_, 1, 1, 1, | |||||||||||||||||||||||||||
| 357 | { type => HASHREF, optional => 1 } ); | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $headers ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$headers ||= {}
MC/DC0%0/1
$headers ||= {}
$headers
Truth table0%0/2
A
A= $headers
| |||||||||||||||||||||||||||||
| 360 | 0 | my $has_ct = 0; | |||||||||||||||||||||||||||
| 361 | 0 | for my $key( keys %{$headers} ) { | |||||||||||||||||||||||||||
| 362 | 0 | ▶ | if (lc($key) =~ qr/^(content_type|content-type)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 0 | $has_ct = 1; | |||||||||||||||||||||||||||
| 364 | 0 | last ; | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 0 | ▶ | unless ( $has_ct ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | require File::Type; | |||||||||||||||||||||||||||
| 369 | 0 | my $ft = File::Type->new; | |||||||||||||||||||||||||||
| 370 | 0 | my $content_type = $ft->checktype_filename( $filename ); | |||||||||||||||||||||||||||
| 371 | 0 | $headers->{'content_type'} = $content_type; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | 0 | ▶ | open my $fh, '<', $filename or die "$!: $filename"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | $self->create_object( $bucket, $key, $fh, $headers ) | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 0 | ▶ | sub copy_object { | ||||||||||||||||||||||||||
|
Subroutine
copy_object: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 378 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 379 | 0 | my( $source_bucket, $source_key, $dest_bucket, $dest_key, $headers ) = @_; | |||||||||||||||||||||||||||
| 380 | 0 | validate_pos( @_, | |||||||||||||||||||||||||||
| 381 | 1, 1, 1, | ||||||||||||||||||||||||||||
| 382 | { type => SCALAR | UNDEF, optional => 1 }, | ||||||||||||||||||||||||||||
| 383 | { type => HASHREF, optional => 1} ); | ||||||||||||||||||||||||||||
| 384 | 0 | ▶ | $headers ||= +{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$headers ||= {}
MC/DC0%0/1
$headers ||= {}
$headers
Truth table0%0/2
A
A= $headers
| |||||||||||||||||||||||||||||
| 385 | 0 | my $source = $self->resource( $source_bucket, $source_key ); | |||||||||||||||||||||||||||
| 386 | $self->create_object( $dest_bucket, $dest_key, '', { | ||||||||||||||||||||||||||||
| 387 | 0 | %{$headers}, | |||||||||||||||||||||||||||
| 388 | 'x-amz-copy-source' => $source, | ||||||||||||||||||||||||||||
| 389 | }); | ||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | sub _normalize_response { | ||||||||||||||||||||||||||
|
Subroutine
_normalize_response: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 393 | 0 | my( $self, $res, $is_head ) = @_; | |||||||||||||||||||||||||||
| 394 | 0 | my %res; | |||||||||||||||||||||||||||
| 395 | 0 | ▶ | while (my($k, $v) = each %{$res->{headers}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 396 | 0 | $res{$k} = $v; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | # remove etag's double quote. | ||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ( my $etag = $res{'etag'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 0 | $res{etag} = _remove_quote( $etag ); | |||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | # make aliases | ||||||||||||||||||||||||||||
| 403 | 0 | $res{content_length} = $res{'content-length'}; | |||||||||||||||||||||||||||
| 404 | 0 | $res{content_type} = $res{'content-type'}; | |||||||||||||||||||||||||||
| 405 | 0 | $res{last_modified} = $res{'last-modified'}; | |||||||||||||||||||||||||||
| 406 | 0 | ▶ | unless ( $is_head ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | 0 | $res{content} = $res->{body}; | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | 0 | return \%res; | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | sub get_object { | ||||||||||||||||||||||||||
|
Subroutine
get_object: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 414 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 415 | 0 | my( $bucket, $key, $headers, $furl_options ) = @_; | |||||||||||||||||||||||||||
| 416 | 0 | validate_pos( @_, 1, 1, | |||||||||||||||||||||||||||
| 417 | { type => HASHREF, optional => 1 }, | ||||||||||||||||||||||||||||
| 418 | { type => HASHREF, optional => 1 }, ); | ||||||||||||||||||||||||||||
| 419 | 0 | my $res = $self->request( 'GET', $bucket, $key, undef, $headers, $furl_options ); | |||||||||||||||||||||||||||
| 420 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | 0 | $self->_normalize_response( $res ); | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | ▶ | sub get_object_to_file { | ||||||||||||||||||||||||||
|
Subroutine
get_object_to_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 427 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 428 | 0 | my( $bucket, $key, $filename ) = @_; | |||||||||||||||||||||||||||
| 429 | 0 | validate_pos( @_, 1, 1, 1 ); | |||||||||||||||||||||||||||
| 430 | 0 | ▶ | open my $fh, '>', $filename or die "$!: $filename"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 0 | $self->get_object( $bucket, $key, {}, { | |||||||||||||||||||||||||||
| 432 | write_file => $fh, | ||||||||||||||||||||||||||||
| 433 | }); | ||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 0 | ▶ | sub head_object { | ||||||||||||||||||||||||||
|
Subroutine
head_object: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 437 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 438 | 0 | my( $bucket, $key, $headers ) = @_; | |||||||||||||||||||||||||||
| 439 | 0 | validate_pos( @_, 1, 1, { type => HASHREF, optional => 1 } ); | |||||||||||||||||||||||||||
| 440 | 0 | my $res = $self->request( 'HEAD', $bucket, $key, undef, $headers ); | |||||||||||||||||||||||||||
| 441 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | 0 | $self->_normalize_response( $res, 1 ); | |||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub delete_object { | ||||||||||||||||||||||||||
|
Subroutine
delete_object: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 448 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 449 | 0 | my( $bucket, $key ) = @_; | |||||||||||||||||||||||||||
| 450 | 0 | validate_pos( @_, 1, 1 ); | |||||||||||||||||||||||||||
| 451 | 0 | my $res = $self->request( 'DELETE', $bucket, $key ); | |||||||||||||||||||||||||||
| 452 | 0 | ▶ | unless ( _http_is_success($res->{code}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | 0 | return $self->error( $res ); | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | 0 | return 1; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | sub clear_error { | ||||||||||||||||||||||||||
|
Subroutine
clear_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 459 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 460 | 0 | delete $self->{_error}; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 464 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 465 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 0 | my $error = Furl::S3::Error->new( $_[0] ); | |||||||||||||||||||||||||||
| 467 | 0 | $self->{_error} = $error; | |||||||||||||||||||||||||||
| 468 | 0 | return ; | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | 0 | $self->{_error}; | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 2 | ▶ | sub _normalize_key { | ||||||||||||||||||||||||||
|
Subroutine
_normalize_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 474 | 2 | my $key = shift; | |||||||||||||||||||||||||||
| 475 | 2 | join '/', map { _uri_escape($_) } split /\//, $key; | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 0 | ▶ | sub _http_is_success { | ||||||||||||||||||||||||||
|
Subroutine
_http_is_success: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 479 | 0 | ▶ | $_[0] >= 200 && $_[0] < 300; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 2 | ▶ | sub _uri_escape { | ||||||||||||||||||||||||||
|
Subroutine
_uri_escape: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 483 | 2 | uri_escape_utf8($_[0], '^A-Za-z0-9\._-'); | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | 4 | 1; | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | __END__ | ||||||||||||||||||||||||||||