File Coverage

lib/AnyEvent/Net/Amazon/S3/Client/Bucket.pm
Criterion Covered Total %
statement 15 32 46.8
branch 0 8 0.0
condition 0 3 0.0
subroutine 5 7 71.4
pod n/a
total 20 50 40.0


line stmt bran cond sub pod time code
1             package AnyEvent::Net::Amazon::S3::Client::Bucket;
2              
3             # ABSTRACT: An easy-to-use Amazon S3 client bucket
4             our $VERSION = 'v0.04.0.80'; # VERSION
5              
6 1     1   2230 use strict;
  1         3  
  1         30  
7 1     1   5 use warnings;
  1         2  
  1         22  
8              
9 1     1   4 use Module::AnyEvent::Helper;
  1         1  
  1         37  
10 1     1   4 use AnyEvent;
  1         2  
  1         227  
11              
12             sub delete_multi_object_async
13             {
14 0     0     my $self = shift;
15 0           my @objects = @_;
16 0 0         return unless( scalar(@objects) );
17              
18             # Since delete can handle up to 1000 requests, be a little bit nicer
19             # and slice up requests and also allow keys to be strings
20             # rather than only objects.
21 0           my $cv = AE::cv;
22 0           my $iter; $iter = sub {
23              
24             my $http_request = AnyEvent::Net::Amazon::S3::Request::DeleteMultiObject->new(
25             s3 => $self->client->s3,
26             bucket => $self->name,
27             keys => [map {
28 0 0   0     if (ref($_)) {
  0 0          
29 0           $_->key
30             } else {
31 0           $_
32             }
33             } splice @objects, 0, ((scalar(@objects) > 1000) ? 1000 : scalar(@objects))]
34             )->http_request;
35              
36             Module::AnyEvent::Helper::bind_scalar($cv, $self->client->_send_request_async($http_request), sub {
37 0           my $last_result = shift->recv;
38 0 0 0       if(!$last_result->is_success() || scalar(@objects) == 0) {
39 0           return $last_result;
40             } else {
41 0           $iter->();
42             }
43 0           });
44 0           };
45 0           $iter->();
46 0           return $cv;
47             }
48              
49 1         14 use Module::AnyEvent::Helper::Filter -as => __PACKAGE__, -target => 'Net::Amazon::S3::Client::Bucket',
50             -transformer => 'Net::Amazon::S3::Client::Bucket',
51             -remove_func => [qw(delete_multi_object)],
52             -translate_func => [qw(_create delete acl location_constraint)],
53             -replace_func => [qw(_send_request _send_request_content _send_request_xpc)],
54             -exclude_func => [qw(list)]
55 1     1   4 ;
  1         1  
56              
57             1;
58              
59             __END__
60              
61             =pod
62              
63             =encoding UTF-8
64              
65             =head1 NAME
66              
67             AnyEvent::Net::Amazon::S3::Client::Bucket - An easy-to-use Amazon S3 client bucket
68              
69             =head1 VERSION
70              
71             version v0.04.0.80
72              
73             =head1 SYNOPSIS
74              
75             # return the bucket name
76             print $bucket->name . "\n";
77              
78             # return the bucket location constraint
79             print "Bucket is in the " . $bucket->location_constraint . "\n";
80              
81             # return the ACL XML
82             my $acl = $bucket->acl;
83              
84             # list objects in the bucket
85             # this returns a L<Data::Stream::Bulk> object which returns a
86             # stream of L<AnyEvent::Net::Amazon::S3::Client::Object> objects, as it may
87             # have to issue multiple API requests
88             my $stream = $bucket->list;
89             until ( $stream->is_done ) {
90             foreach my $object ( $stream->items ) {
91             ...
92             }
93             }
94              
95             # or list by a prefix
96             my $prefix_stream = $bucket->list( { prefix => 'logs/' } );
97              
98             # returns a L<AnyEvent::Net::Amazon::S3::Client::Object>, which can then
99             # be used to get or put
100             my $object = $bucket->object( key => 'this is the key' );
101              
102             # delete the bucket (it must be empty)
103             $bucket->delete;
104              
105             =head1 DESCRIPTION
106              
107             This module represents buckets.
108              
109             This module provides the same interface as L<Net::Amazon::S3::Client::Bucket>.
110             In addition, some asynchronous methods returning AnyEvent condition variable are added.
111              
112             =for test_synopsis no strict 'vars'
113              
114             =head1 METHODS
115              
116             All L<Net::Amazon::S3::Client::Bucket> methods are available.
117             In addition, there are the following asynchronous methods.
118             Arguments of the methods are identical as original but return value becomes L<AnyEvent> condition variable.
119             You can get actual return value by calling C<shift-E<gt>recv()>.
120              
121             =over 4
122              
123             =item acl_async
124              
125             =item delete_async
126              
127             =item list_async
128              
129             =item location_constraint_async
130              
131             =item delete_multi_object_async
132              
133             =back
134              
135             =head2 list
136              
137             In addition to described in L<Net::Amazon::S3::Client::Bucket>,
138             C<max_keys> and C<marker> options can be accepted.
139              
140             =for Pod::Coverage object object_class
141              
142             =head1 AUTHOR
143              
144             Yasutaka ATARASHI <yakex@cpan.org>
145              
146             =head1 COPYRIGHT AND LICENSE
147              
148             This software is copyright (c) 2012 by Yasutaka ATARASHI.
149              
150             This is free software; you can redistribute it and/or modify it under
151             the same terms as the Perl 5 programming language system itself.
152              
153             =cut