| 1 | package Net::Amazon::S3::Client::Bucket; | ||||||||||||||||||||
| 2 | 99 | $Net::Amazon::S3::Client::Bucket::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 Data::Stream::Bulk::Callback; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 99 | ▶ | use MooseX::Types::DateTime::MoreCoercions 0.07 qw( DateTime ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | # ABSTRACT: An easy-to-use Amazon S3 client bucket | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 99 | has 'client' => | |||||||||||||||||||
| 11 | ( is => 'ro', isa => 'Net::Amazon::S3::Client', required => 1 ); | ||||||||||||||||||||
| 12 | 99 | has 'name' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||
| 13 | 99 | has 'creation_date' => | |||||||||||||||||||
| 14 | ( is => 'ro', isa => DateTime, coerce => 1, required => 0 ); | ||||||||||||||||||||
| 15 | 99 | has 'owner_id' => ( is => 'ro', isa => 'Str', required => 0 ); | |||||||||||||||||||
| 16 | 99 | has 'owner_display_name' => ( is => 'ro', isa => 'Str', required => 0 ); | |||||||||||||||||||
| 17 | has 'region' => ( | ||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||
| 19 | lazy => 1, | ||||||||||||||||||||
| 20 | predicate => 'has_region', | ||||||||||||||||||||
| 21 | 0 | ▶ | default => sub { $_[0]->location_constraint }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 22 | 99 | ); | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 99 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 17 | ▶ | sub _create { | ||||||||||||||||||
|
Subroutine
_create: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 28 | 17 | my ($self, %conf) = @_; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | my $response = $self->_perform_operation ( | ||||||||||||||||||||
| 31 | 'Net::Amazon::S3::Operation::Bucket::Create', | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | (acl => $conf{acl}) x!! defined $conf{acl}, | ||||||||||||||||||||
| 34 | (acl_short => $conf{acl_short}) x!! defined $conf{acl_short}, | ||||||||||||||||||||
| 35 | (location_constraint => $conf{location_constraint}) x!! defined $conf{location_constraint}, | ||||||||||||||||||||
| 36 | 17 | ); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 6 | ▶ | return unless $response->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 6 | return $response->http_response; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 6 | ▶ | sub delete { | ||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 44 | 6 | my $self = shift; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 6 | my $response = $self->_perform_operation ( | |||||||||||||||||||
| 47 | 'Net::Amazon::S3::Operation::Bucket::Delete', | ||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | ▶ | return unless $response->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 1 | return $response->http_response; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 5 | ▶ | sub acl { | ||||||||||||||||||
|
Subroutine
acl: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 55 | 5 | my $self = shift; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 5 | my $response = $self->_perform_operation ( | |||||||||||||||||||
| 58 | 'Net::Amazon::S3::Operation::Bucket::Acl::Fetch', | ||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | ▶ | return if $response->is_error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 1 | return $response->http_response->content; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 9 | ▶ | sub set_acl { | ||||||||||||||||||
|
Subroutine
set_acl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 66 | 9 | my ($self, %params) = @_; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 9 | my $response = $self->_perform_operation ( | |||||||||||||||||||
| 69 | 'Net::Amazon::S3::Operation::Bucket::Acl::Set', | ||||||||||||||||||||
| 70 | %params, | ||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 5 | return $response->is_success; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 5 | ▶ | sub add_tags { | ||||||||||||||||||
|
Subroutine
add_tags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 77 | 5 | my ($self, %params) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | my $response = $self->_perform_operation ( | ||||||||||||||||||||
| 80 | 'Net::Amazon::S3::Operation::Bucket::Tags::Add', | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | tags => $params{tags}, | ||||||||||||||||||||
| 83 | 5 | ); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 1 | return $response->is_success; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 5 | ▶ | sub delete_tags { | ||||||||||||||||||
|
Subroutine
delete_tags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 89 | 5 | my ($self, $conf) = @_; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 5 | my $response = $self->_perform_operation ( | |||||||||||||||||||
| 92 | 'Net::Amazon::S3::Operation::Bucket::Tags::Delete', | ||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 1 | return $response->is_success; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 1 | ▶ | sub location_constraint { | ||||||||||||||||||
|
Subroutine
location_constraint: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||
| 99 | 1 | my $self = shift; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | my $response = $self->_perform_operation ( | |||||||||||||||||||
| 102 | 'Net::Amazon::S3::Operation::Bucket::Location', | ||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | return unless $response->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 0 | return $response->location; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 87 | ▶ | sub object_class { 'Net::Amazon::S3::Client::Object' } | ||||||||||||||||||
|
Subroutine
object_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 8 | ▶ | sub list { | ||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 112 | 8 | my ( $self, $conf ) = @_; | |||||||||||||||||||
| 113 | 8 | ▶ | $conf ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$conf ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||||||||
| 114 | 8 | my $prefix = $conf->{prefix}; | |||||||||||||||||||
| 115 | 8 | my $delimiter = $conf->{delimiter}; | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 8 | my $marker = undef; | |||||||||||||||||||
| 118 | 8 | my $end = 0; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | return Data::Stream::Bulk::Callback->new( | ||||||||||||||||||||
| 121 | 8 | ▶ | callback => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.4
| |||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 8 | ▶ | return undef if $end; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 8 | my $response = $self->_perform_operation ( | |||||||||||||||||||
| 126 | 'Net::Amazon::S3::Operation::Objects::List', | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | marker => $marker, | ||||||||||||||||||||
| 129 | prefix => $prefix, | ||||||||||||||||||||
| 130 | delimiter => $delimiter, | ||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 4 | ▶ | return unless $response->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 4 | my @objects; | |||||||||||||||||||
| 136 | 4 | foreach my $node ($response->contents) { | |||||||||||||||||||
| 137 | push @objects, $self->object_class->new ( | ||||||||||||||||||||
| 138 | client => $self->client, | ||||||||||||||||||||
| 139 | bucket => $self, | ||||||||||||||||||||
| 140 | key => $node->{key}, | ||||||||||||||||||||
| 141 | etag => $node->{etag}, | ||||||||||||||||||||
| 142 | size => $node->{size}, | ||||||||||||||||||||
| 143 | last_modified_raw => $node->{last_modified}, | ||||||||||||||||||||
| 144 | 5 | ); | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 4 | ▶ | return undef unless @objects; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 3 | ▶ | $end = 1 unless $response->is_truncated; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 3 | ▶ | $marker = $response->next_marker | ||||||||||||||||||
|
Condition33%1/3
$response->next_marker || $objects[-1]->key
MC/DC0%0/2
$response->next_marker || $objects[-1]->key
$response->next_marker
$objects[-1]->key
Truth table33%1/3
A || B
A= $response->next_markerB= $objects[-1]->key
| |||||||||||||||||||||
| 152 | || $objects[-1]->key; | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 3 | return \@objects; | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | 8 | ); | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 5 | ▶ | sub delete_multi_object { | ||||||||||||||||||
|
Subroutine
delete_multi_object: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||
| 160 | 5 | my $self = shift; | |||||||||||||||||||
| 161 | 5 | my @objects = @_; | |||||||||||||||||||
| 162 | 5 | ▶ | return unless( scalar(@objects) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | # Since delete can handle up to 1000 requests, be a little bit nicer | ||||||||||||||||||||
| 165 | # and slice up requests and also allow keys to be strings | ||||||||||||||||||||
| 166 | # rather than only objects. | ||||||||||||||||||||
| 167 | 5 | my $last_result; | |||||||||||||||||||
| 168 | 5 | ▶ | while (scalar(@objects) > 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 169 | my $response = $self->_perform_operation ( | ||||||||||||||||||||
| 170 | 'Net::Amazon::S3::Operation::Objects::Delete', | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | keys => [ | ||||||||||||||||||||
| 173 | 5 | ▶ | map { ref ($_) ? $_->key : $_ } | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 174 | splice @objects, 0, ((scalar(@objects) > 1000) ? 1000 : scalar(@objects)) | ||||||||||||||||||||
| 175 | ] | ||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 1 | $last_result = $response; | |||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 1 | ▶ | last unless $response->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | 1 | return $last_result->http_response; | |||||||||||||||||||
| 183 | } | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 82 | ▶ | sub object { | ||||||||||||||||||
|
Subroutine
object: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 186 | 82 | my ( $self, %conf ) = @_; | |||||||||||||||||||
| 187 | 82 | return $self->object_class->new( | |||||||||||||||||||
| 188 | client => $self->client, | ||||||||||||||||||||
| 189 | bucket => $self, | ||||||||||||||||||||
| 190 | %conf, | ||||||||||||||||||||
| 191 | ); | ||||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 139 | ▶ | sub _perform_operation { | ||||||||||||||||||
|
Subroutine
_perform_operation: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 195 | 139 | my ($self, $operation, %params) = @_; | |||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 139 | $self->client->_perform_operation ($operation => ( | |||||||||||||||||||
| 198 | bucket => $self->name, | ||||||||||||||||||||
| 199 | %params, | ||||||||||||||||||||
| 200 | )); | ||||||||||||||||||||
| 201 | } | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | 99 | 1; | |||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||