File Coverage

blib/lib/AWS/S3/Request/CreateBucket.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 3 3 100.0
pod 0 1 0.0
total 20 22 90.9


line stmt bran cond sub pod time code
1              
2             package AWS::S3::Request::CreateBucket;
3 1     1   865 use Moose;
  1         20  
  1         9  
4              
5 1     1   9790 use AWS::S3::Signer;
  1         5  
  1         463  
6              
7             with 'AWS::S3::Roles::Request';
8              
9             has 'bucket' => (
10             is => 'ro',
11             isa => 'Str',
12             required => 1,
13             );
14              
15             has 'location' => (
16             is => 'ro',
17             isa => 'Maybe[Str]',
18             lazy => 1,
19             required => 0,
20             default => sub { shift->s3->region || $ENV{AWS_REGION} },
21             );
22              
23             has '+_expect_nothing' => ( default => 1 );
24              
25             sub request {
26 3     3 0 9 my $s = shift;
27              
28             # By default the bucket is put in us-east-1. But if you _ask_ for
29             # us-east-1 you get an error.
30 3         8 my $xml = q{};
31 3 100 66     219 if ( $s->location && $s->location ne 'us-east-1' ) {
32 2         4 $xml = <<"XML";
33             <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
34 2         82 <LocationConstraint>@{[ $s->location ]}</LocationConstraint>
35             </CreateBucketConfiguration>
36             XML
37             }
38              
39 3         124 my $signer = AWS::S3::Signer->new(
40             s3 => $s->s3,
41             method => 'PUT',
42             uri => $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/',
43             content_type => 'text/plain',
44             content_md5 => '',
45             content => \$xml,
46             );
47              
48 3         26874 return $s->_send_request(
49             $signer->method => $signer->uri => {
50             Authorization => $signer->auth_header,
51             Date => $signer->date,
52             'content-type' => 'text/plain',
53             },
54             $xml
55             );
56             }
57              
58             __PACKAGE__->meta->make_immutable;