AWS-S3

 view release on metacpan or  search on metacpan

lib/AWS/S3/Request/CreateBucket.pm  view on Meta::CPAN


package AWS::S3::Request::CreateBucket;
use Moose;

with 'AWS::S3::Roles::Request';

has 'bucket' => (
    is       => 'ro',
    isa      => 'AWS::S3::BucketName',
    required => 1,
);

has 'location' => (
    is       => 'ro',
    isa      => 'Maybe[Str]',
    lazy     => 1,
    required => 0,
    default  => sub { shift->s3->region || $ENV{AWS_REGION} },
);

has '+_expect_nothing' => ( default => 1 );

sub request {
    my $s = shift;

    # By default the bucket is put in us-east-1. But if you _ask_ for
    # us-east-1 you get an error.
    my $xml = q{};
    if ( $s->location && $s->location ne 'us-east-1' ) {
        $xml = <<"XML";
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
  <LocationConstraint>@{[ $s->_xml_escape( $s->location ) ]}</LocationConstraint>
</CreateBucketConfiguration>
XML
    }

    return $s->_send_request(
        PUT => URI->new( $s->protocol . '://' . $s->bucket . '.' . $s->endpoint . '/' ) => {
            Date           => $s->_http_date,
            'content-type' => 'text/plain',
        },
        $xml
    );
}

__PACKAGE__->meta->make_immutable;



( run in 1.218 second using v1.01-cache-2.11-cpan-0e0213f3164 )