| 1 | package Net::Amazon::S3; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Use the Amazon S3 - Simple Storage Service | ||||||||||||||||||||||||||||
| 3 | 99 | $Net::Amazon::S3::VERSION = '0.992'; | |||||||||||||||||||||||||||
| 4 | 99 | ▶ | use Moose 0.85; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 99 | ▶ | use MooseX::StrictConstructor 0.16; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 99 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 99 | ▶ | use Digest::HMAC_SHA1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 99 | ▶ | use Safe::Isa (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 99 | ▶ | use Net::Amazon::S3::Bucket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 99 | ▶ | use Net::Amazon::S3::Client; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 99 | ▶ | use Net::Amazon::S3::Client::Bucket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 99 | ▶ | use Net::Amazon::S3::Client::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 99 | ▶ | use Net::Amazon::S3::Error::Handler::Legacy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 99 | ▶ | use Net::Amazon::S3::HTTPRequest; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 99 | ▶ | use Net::Amazon::S3::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 99 | ▶ | use Net::Amazon::S3::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Acl::Fetch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Acl::Set; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Create; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Delete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Location; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Tags::Add; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 99 | ▶ | use Net::Amazon::S3::Operation::Bucket::Tags::Delete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 99 | ▶ | use Net::Amazon::S3::Operation::Buckets::List; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Acl::Fetch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Acl::Set; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Add; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Delete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Fetch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Head; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Restore; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Tags::Add; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Tags::Delete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Upload::Abort; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Upload::Complete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Upload::Create; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Upload::Part; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 99 | ▶ | use Net::Amazon::S3::Operation::Object::Upload::Parts; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 99 | ▶ | use Net::Amazon::S3::Operation::Objects::Delete; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 99 | ▶ | use Net::Amazon::S3::Operation::Objects::List; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 99 | ▶ | use Net::Amazon::S3::Signature::V2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 99 | ▶ | use Net::Amazon::S3::Signature::V4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 99 | ▶ | use Net::Amazon::S3::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 99 | ▶ | use Net::Amazon::S3::Vendor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 99 | ▶ | use Net::Amazon::S3::Vendor::Amazon; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 99 | ▶ | use LWP::UserAgent::Determined; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 99 | ▶ | use URI::Escape qw(uri_escape_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 99 | my $AMAZON_S3_HOST = 's3.amazonaws.com'; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 99 | has authorization_context => ( | |||||||||||||||||||||||||||
| 54 | is => 'ro', | ||||||||||||||||||||||||||||
| 55 | isa => 'Net::Amazon::S3::Authorization', | ||||||||||||||||||||||||||||
| 56 | required => 0, | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | handles => { | ||||||||||||||||||||||||||||
| 59 | aws_access_key_id => 'aws_access_key_id', | ||||||||||||||||||||||||||||
| 60 | aws_secret_access_key => 'aws_secret_access_key', | ||||||||||||||||||||||||||||
| 61 | aws_session_token => 'aws_session_token', | ||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 99 | has vendor => ( | |||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||
| 67 | isa => 'Net::Amazon::S3::Vendor', | ||||||||||||||||||||||||||||
| 68 | required => 1, | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | handles => { | ||||||||||||||||||||||||||||
| 71 | authorization_method => 'authorization_method', | ||||||||||||||||||||||||||||
| 72 | host => 'host', | ||||||||||||||||||||||||||||
| 73 | secure => 'use_https', | ||||||||||||||||||||||||||||
| 74 | use_virtual_host => 'use_virtual_host', | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 99 | has 'timeout' => ( is => 'ro', isa => 'Num', required => 0, default => 30 ); | |||||||||||||||||||||||||||
| 79 | 99 | has 'retry' => ( is => 'ro', isa => 'Bool', required => 0, default => 0 ); | |||||||||||||||||||||||||||
| 80 | 99 | has 'ua' | |||||||||||||||||||||||||||
| 81 | => is => 'rw' | ||||||||||||||||||||||||||||
| 82 | => isa => 'LWP::UserAgent' | ||||||||||||||||||||||||||||
| 83 | => required => 0 | ||||||||||||||||||||||||||||
| 84 | => lazy => 1 | ||||||||||||||||||||||||||||
| 85 | => builder => '_build_ua' | ||||||||||||||||||||||||||||
| 86 | ; | ||||||||||||||||||||||||||||
| 87 | 99 | has 'err' => ( is => 'rw', isa => 'Maybe[Str]', required => 0 ); | |||||||||||||||||||||||||||
| 88 | 99 | has 'errstr' => ( is => 'rw', isa => 'Maybe[Str]', required => 0 ); | |||||||||||||||||||||||||||
| 89 | 99 | has keep_alive_cache_size => ( is => 'ro', isa => 'Int', required => 0, default => 10 ); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 99 | has error_handler_class => ( | |||||||||||||||||||||||||||
| 92 | is => 'ro', | ||||||||||||||||||||||||||||
| 93 | lazy => 1, | ||||||||||||||||||||||||||||
| 94 | default => 'Net::Amazon::S3::Error::Handler::Legacy', | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | has error_handler => ( | ||||||||||||||||||||||||||||
| 98 | is => 'ro', | ||||||||||||||||||||||||||||
| 99 | lazy => 1, | ||||||||||||||||||||||||||||
| 100 | 107 | ▶ | default => sub { $_[0]->error_handler_class->new (s3 => $_[0]) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 99 | ); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 99 | has bucket_class => ( | |||||||||||||||||||||||||||
| 104 | is => 'ro', | ||||||||||||||||||||||||||||
| 105 | init_arg => undef, | ||||||||||||||||||||||||||||
| 106 | lazy => 1, | ||||||||||||||||||||||||||||
| 107 | default => 'Net::Amazon::S3::Bucket', | ||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 415 | ▶ | sub _build_arg_authorization_context { | ||||||||||||||||||||||||||
|
Subroutine
_build_arg_authorization_context: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 111 | 415 | my ($args) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 415 | my $aws_access_key_id = delete $args->{aws_access_key_id}; | |||||||||||||||||||||||||||
| 114 | 415 | my $aws_secret_access_key = delete $args->{aws_secret_access_key}; | |||||||||||||||||||||||||||
| 115 | 415 | my $use_iam_role = delete $args->{use_iam_role}; | |||||||||||||||||||||||||||
| 116 | 415 | my $aws_session_token = delete $args->{aws_session_token}; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 415 | ▶ | if ($args->{authorization_context}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | return $args->{authorization_context}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 415 | ▶ | if ($use_iam_role || $aws_session_token) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$use_iam_role or $aws_session_token
MC/DC50%1/2
$use_iam_role or $aws_session_token
$use_iam_role
$aws_session_token
Truth table66%2/3
A or B
A= $use_iam_roleB= $aws_session_token
| |||||||||||||||||||||||||||||
| 123 | 1 | require Net::Amazon::S3::Authorization::IAM; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | return Net::Amazon::S3::Authorization::IAM->new ( | |||||||||||||||||||||||||||
| 126 | aws_access_key_id => $aws_access_key_id, | ||||||||||||||||||||||||||||
| 127 | aws_secret_access_key => $aws_secret_access_key, | ||||||||||||||||||||||||||||
| 128 | aws_session_token => $aws_session_token, | ||||||||||||||||||||||||||||
| 129 | ) | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 414 | require Net::Amazon::S3::Authorization::Basic; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 414 | return Net::Amazon::S3::Authorization::Basic->new ( | |||||||||||||||||||||||||||
| 135 | aws_access_key_id => $aws_access_key_id, | ||||||||||||||||||||||||||||
| 136 | aws_secret_access_key => $aws_secret_access_key, | ||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 415 | ▶ | sub _build_arg_vendor { | ||||||||||||||||||||||||||
|
Subroutine
_build_arg_vendor: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 141 | 415 | my ($args) = @_; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | my %backward = | ||||||||||||||||||||||||||||
| 144 | 1288 | map { $_ => delete $args->{$_} } | |||||||||||||||||||||||||||
| 145 | 415 | grep { exists $args->{$_} } | |||||||||||||||||||||||||||
| 146 | qw[ host secure use_virtual_host authorization_method ] | ||||||||||||||||||||||||||||
| 147 | ; | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | return $args->{vendor} | ||||||||||||||||||||||||||||
| 150 | 415 | ▶ | if $args->{vendor}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | $backward{host} = $AMAZON_S3_HOST | ||||||||||||||||||||||||||||
| 153 | 413 | ▶ | unless exists $backward{host}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | $backward{use_https} = delete $backward{secure} | ||||||||||||||||||||||||||||
| 156 | 413 | ▶ | if exists $backward{secure}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 413 | ▶ | my $vendor_class = $backward{host} eq $AMAZON_S3_HOST | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | ? 'Net::Amazon::S3::Vendor::Amazon' | ||||||||||||||||||||||||||||
| 160 | : 'Net::Amazon::S3::Vendor' | ||||||||||||||||||||||||||||
| 161 | ; | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 413 | return $vendor_class->new (%backward); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 415 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | 415 | my ($orig, $class) = (shift, shift); | |||||||||||||||||||||||||||
| 168 | 415 | my $args = $class->$orig (@_); | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # support compat authorization arguments | ||||||||||||||||||||||||||||
| 171 | 415 | $args->{authorization_context} = _build_arg_authorization_context $args; | |||||||||||||||||||||||||||
| 172 | 415 | $args->{vendor} = _build_arg_vendor $args; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 415 | $args; | |||||||||||||||||||||||||||
| 175 | 99 | }; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub _build_ua { | ||||||||||||||||||||||||||
|
Subroutine
_build_ua: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 179 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | my $ua; | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ( $self->retry ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | $ua = LWP::UserAgent::Determined->new( | |||||||||||||||||||||||||||
| 184 | keep_alive => $self->keep_alive_cache_size, | ||||||||||||||||||||||||||||
| 185 | requests_redirectable => [qw(GET HEAD DELETE PUT POST)], | ||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||
| 187 | 0 | $ua->timing('1,2,4,8,16,32'); | |||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||
| 189 | 0 | $ua = LWP::UserAgent->new( | |||||||||||||||||||||||||||
| 190 | keep_alive => $self->keep_alive_cache_size, | ||||||||||||||||||||||||||||
| 191 | requests_redirectable => [qw(GET HEAD DELETE PUT POST)], | ||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | $ua->timeout( $self->timeout ); | |||||||||||||||||||||||||||
| 196 | 0 | $ua->env_proxy; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | return $ua; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 5 | ▶ | sub buckets { | ||||||||||||||||||||||||||
|
Subroutine
buckets: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 5 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 5 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||
| 205 | 'Net::Amazon::S3::Operation::Buckets::List', | ||||||||||||||||||||||||||||
| 206 | %args, | ||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 4 | ▶ | return unless $response->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 2 | my $owner_id = $response->owner_id;; | |||||||||||||||||||||||||||
| 212 | 2 | my $owner_displayname = $response->owner_displayname; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 2 | my @buckets; | |||||||||||||||||||||||||||
| 215 | 2 | foreach my $bucket ($response->buckets) { | |||||||||||||||||||||||||||
| 216 | push @buckets, $self->bucket_class->new ( | ||||||||||||||||||||||||||||
| 217 | account => $self, | ||||||||||||||||||||||||||||
| 218 | bucket => $bucket->{name}, | ||||||||||||||||||||||||||||
| 219 | creation_date => $bucket->{creation_date}, | ||||||||||||||||||||||||||||
| 220 | 4 | ); | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | return +{ | ||||||||||||||||||||||||||||
| 225 | 2 | owner_id => $owner_id, | |||||||||||||||||||||||||||
| 226 | owner_displayname => $owner_displayname, | ||||||||||||||||||||||||||||
| 227 | buckets => \@buckets, | ||||||||||||||||||||||||||||
| 228 | }; | ||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 27 | ▶ | sub add_bucket { | ||||||||||||||||||||||||||
|
Subroutine
add_bucket: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | 27 | my $self = shift; | |||||||||||||||||||||||||||
| 233 | 27 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 27 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||
| 236 | 'Net::Amazon::S3::Operation::Bucket::Create', | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | %args, | ||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 11 | ▶ | return unless $response->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 7 | return $self->bucket ($args{bucket}); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 149 | ▶ | sub bucket { | ||||||||||||||||||||||||||
|
Subroutine
bucket: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 149 | my $self = shift; | |||||||||||||||||||||||||||
| 248 | 149 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_); | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | return $args{bucket} | ||||||||||||||||||||||||||||
| 251 | 149 | ▶ | if $args{bucket}->$Safe::Isa::_isa ($self->bucket_class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | return $self->bucket_class->new ({ | ||||||||||||||||||||||||||||
| 254 | account => $self, | ||||||||||||||||||||||||||||
| 255 | bucket => $args{bucket}, | ||||||||||||||||||||||||||||
| 256 | (region => $args{region}) x defined $args{region}, | ||||||||||||||||||||||||||||
| 257 | 148 | }); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 9 | ▶ | sub delete_bucket { | ||||||||||||||||||||||||||
|
Subroutine
delete_bucket: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 261 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 262 | 9 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_); | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | croak 'must specify bucket' | ||||||||||||||||||||||||||||
| 265 | 9 | ▶ | unless defined $args{bucket}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 9 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||
| 268 | 'Net::Amazon::S3::Operation::Bucket::Delete', | ||||||||||||||||||||||||||||
| 269 | %args, | ||||||||||||||||||||||||||||
| 270 | ); | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 5 | ▶ | return unless $response->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 1 | return 1; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 16 | ▶ | sub list_bucket { | ||||||||||||||||||||||||||
|
Subroutine
list_bucket: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 278 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 279 | 16 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_); | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 16 | my $response = $self->_perform_operation ( | |||||||||||||||||||||||||||
| 282 | 'Net::Amazon::S3::Operation::Objects::List', | ||||||||||||||||||||||||||||
| 283 | %args, | ||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 8 | ▶ | return unless $response->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 5 | my $return = { | |||||||||||||||||||||||||||
| 289 | bucket => $response->bucket, | ||||||||||||||||||||||||||||
| 290 | prefix => $response->prefix, | ||||||||||||||||||||||||||||
| 291 | marker => $response->marker, | ||||||||||||||||||||||||||||
| 292 | next_marker => $response->next_marker, | ||||||||||||||||||||||||||||
| 293 | max_keys => $response->max_keys, | ||||||||||||||||||||||||||||
| 294 | is_truncated => $response->is_truncated, | ||||||||||||||||||||||||||||
| 295 | }; | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 5 | my @keys; | |||||||||||||||||||||||||||
| 298 | 5 | foreach my $node ($response->contents) { | |||||||||||||||||||||||||||
| 299 | push @keys, { | ||||||||||||||||||||||||||||
| 300 | key => $node->{key}, | ||||||||||||||||||||||||||||
| 301 | last_modified => $node->{last_modified}, | ||||||||||||||||||||||||||||
| 302 | etag => $node->{etag}, | ||||||||||||||||||||||||||||
| 303 | size => $node->{size}, | ||||||||||||||||||||||||||||
| 304 | storage_class => $node->{storage_class}, | ||||||||||||||||||||||||||||
| 305 | owner_id => $node->{owner}{id}, | ||||||||||||||||||||||||||||
| 306 | owner_displayname => $node->{owner}{displayname}, | ||||||||||||||||||||||||||||
| 307 | 7 | }; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | 5 | $return->{keys} = \@keys; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 5 | ▶ | if ( $args{delimiter} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 2 | $return->{common_prefixes} = [ $response->common_prefixes ]; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 5 | return $return; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 4 | ▶ | sub list_bucket_all { | ||||||||||||||||||||||||||
|
Subroutine
list_bucket_all: called CC=5 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||
| 319 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 320 | 4 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket (\@_); | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 4 | my $bucket = $args{bucket}; | |||||||||||||||||||||||||||
| 323 | 4 | ▶ | croak 'must specify bucket' unless $bucket; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 4 | my $response = $self->list_bucket (%args); | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | return $response unless $response->{is_truncated}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | my $all = $response; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | while (1) { | |||||||||||||||||||||||||||
| 330 | my $next_marker = $response->{next_marker} | ||||||||||||||||||||||||||||
| 331 | 0 | ▶ | || $response->{keys}->[-1]->{key}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$response->{'next_marker'} || $response->{'keys'}[-1]{'key'}
MC/DC0%0/2
$response->{'next_marker'} || $response->{'keys'}[-1]{'key'}
$response->{'next_marker'}
$response->{'keys'}[-1]{'key'}
Truth table0%0/3
A || B
A= $response->{'next_marker'}B= $response->{'keys'}[-1]{'key'}
| |||||||||||||||||||||||||||||
| 332 | 0 | $response = $self->list_bucket ( | |||||||||||||||||||||||||||
| 333 | %args, | ||||||||||||||||||||||||||||
| 334 | marker => $next_marker, | ||||||||||||||||||||||||||||
| 335 | ); | ||||||||||||||||||||||||||||
| 336 | 0 | push @{ $all->{keys} }, @{ $response->{keys} }; | |||||||||||||||||||||||||||
| 337 | 0 | ▶ | last unless $response->{is_truncated}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | delete $all->{is_truncated}; | |||||||||||||||||||||||||||
| 341 | 0 | delete $all->{next_marker}; | |||||||||||||||||||||||||||
| 342 | 0 | return $all; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | # compat wrapper; deprecated as of 2005-03-23 | ||||||||||||||||||||||||||||
| 346 | 2 | ▶ | sub add_key { | ||||||||||||||||||||||||||
|
Subroutine
add_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 347 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 348 | 2 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (\@_); | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 2 | my $bucket = $self->bucket (delete $args{bucket}); | |||||||||||||||||||||||||||
| 351 | 2 | return $bucket->add_key (%args); | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | # compat wrapper; deprecated as of 2005-03-23 | ||||||||||||||||||||||||||||
| 355 | 2 | ▶ | sub get_key { | ||||||||||||||||||||||||||
|
Subroutine
get_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 356 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 357 | 2 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (\@_); | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 2 | my $bucket = $self->bucket (delete $args{bucket}); | |||||||||||||||||||||||||||
| 360 | 2 | return $bucket->get_key (%args); | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | # compat wrapper; deprecated as of 2005-03-23 | ||||||||||||||||||||||||||||
| 364 | 1 | ▶ | sub head_key { | ||||||||||||||||||||||||||
|
Subroutine
head_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 365 | 1 | my ( $self, $conf ) = @_; | |||||||||||||||||||||||||||
| 366 | 1 | my $bucket = $self->bucket (delete $conf->{bucket}); | |||||||||||||||||||||||||||
| 367 | 1 | return $bucket->head_key( $conf->{key} ); | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | # compat wrapper; deprecated as of 2005-03-23 | ||||||||||||||||||||||||||||
| 371 | 2 | ▶ | sub delete_key { | ||||||||||||||||||||||||||
|
Subroutine
delete_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 372 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 373 | 2 | my %args = Net::Amazon::S3::Utils->parse_arguments_with_bucket_and_object (\@_); | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 2 | my $bucket = $self->bucket (delete $args{bucket}); | |||||||||||||||||||||||||||
| 376 | 2 | return $bucket->delete_key (%args); | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 210 | ▶ | sub _perform_operation { | ||||||||||||||||||||||||||
|
Subroutine
_perform_operation: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 380 | 210 | my ($self, $operation, %params) = @_; | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 210 | my $error_handler = delete $params{error_handler}; | |||||||||||||||||||||||||||
| 383 | 210 | ▶ | $error_handler = $self->error_handler unless defined $error_handler; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 210 | my $request_class = $operation . '::Request'; | |||||||||||||||||||||||||||
| 386 | 210 | my $response_class = $operation . '::Response'; | |||||||||||||||||||||||||||
| 387 | 210 | my $filename = delete $params{filename}; | |||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 210 | my $request = $request_class->new (s3 => $self, %params); | |||||||||||||||||||||||||||
| 390 | 210 | my $http_response = $self->ua->request ($request->http_request, $filename); | |||||||||||||||||||||||||||
| 391 | 210 | my $response = $response_class->new (http_response => $http_response); | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 210 | $error_handler->handle_error ($response); | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 138 | return $response; | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 394 | ▶ | sub _urlencode { | ||||||||||||||||||||||||||
|
Subroutine
_urlencode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 399 | 394 | my ( $self, $unencoded ) = @_; | |||||||||||||||||||||||||||
| 400 | 394 | return uri_escape_utf8( $unencoded, '^A-Za-z0-9_~\-\.' ); | |||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 99 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 99 | 1; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | __END__ | ||||||||||||||||||||||||||||