S3.pm

filter: Statementstmt 95.1% 78 / 82 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.2% 20 / 21 Podpod 80.0% 4 / 5 totaltotal 92.3% 109 / 118 CC 7 SCAR 6.8
CC
7
Cov
92%
__ANON__
6.0
add_bucket
4.0
buckets
2.0
CRAP 2.0
« S3/Request/SetBucketPolicy.pm ↑ Summary S3/Roles/BucketAction.pm »
1  
2 package AWS::S3;
3  
4 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use LWP::UserAgent::Determined;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Class::Load 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Log::Any qw( $LOG );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use AWS::S3::ResponseParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use AWS::S3::Owner;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use AWS::S3::Bucket;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 our $VERSION = '2.00';
18  
19 6 has [qw/access_key_id secret_access_key/] => ( is => 'ro', isa => 'Str' );
20  
21 has 'session_token' => (
22 is => 'ro',
23 isa => 'Maybe[Str]',
24 lazy => 1,
25 5 ▶ default => sub { $ENV{AWS_SESSION_TOKEN} },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 6 );
27  
28 has 'region' => (
29 is => 'ro',
30 isa => 'Maybe[Str]',
31 lazy => 1,
32 5 ▶ default => sub { $ENV{AWS_REGION} },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 6 );
34  
35 6 has 'secure' => (
36 is => 'ro',
37 isa => 'Bool',
38 lazy => 1,
39 default => 0
40 );
41  
42 has 'endpoint' => (
43 is => 'ro',
44 isa => 'Str',
45 lazy => 1,
46 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
47 0 my ( $s ) = @_;
48  
49 0 ▶ if ( my $region = $s->region ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $region = $s->region) { } 0 0 0
50 0 return "s3.$region.amazonaws.com"
51 } else {
52 0 return "s3.amazonaws.com"
53 }
54 },
55 6 );
56  
57 has 'ua' => (
58 is => 'ro',
59 isa => 'LWP::UserAgent',
60 7 ▶ default => sub { LWP::UserAgent::Determined->new }
Subroutine __ANON__: called CC=1 SCAR=0.0
61 6 );
62  
63 has 'honor_leading_slashes' => (
64 is => 'ro',
65 isa => 'Bool',
66 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
67 6 );
68  
69 34 ▶sub request {
Subroutine request: called CC=1 SCAR=0.0
Pod undocumented
70 34 my ( $s, $type, %args ) = @_;
71  
72 34 my $class = "AWS::S3::Request::$type";
73  
74 34 load_class( $class );
75 34 return $class->new( %args, s3 => $s, type => $type );
76 } # end request()
77  
78 2 ▶sub owner {
Subroutine owner: called CC=1 SCAR=0.0
Pod documented
79 2 my $s = shift;
80  
81 2 my $type = 'ListAllMyBuckets';
82 2 my $request = $s->request( $type );
83 2 my $response = $request->request();
84  
85 # Linode/Akamai E3 endpoints do not include the `xmlns` in
86 # ListAllMyBuckets, so use the localname to work with or
87 # without a declared XML namespace.
88 2 my $xml = $response->xml;
89 2 my ($node) = $xml->getElementsByLocalName('Owner');
90 2 return AWS::S3::Owner->new(
91 id => $node->getElementsByLocalName('ID')->string_value,
92 display_name => $node->getElementsByLocalName('DisplayName')->string_value,
93 );
94 } # end owner()
95  
96 7 ▶sub buckets {
Subroutine buckets: called CC=2 SCAR=6.9
Pod documented
97 7 my ( $s ) = @_;
98  
99 7 my $type = 'ListAllMyBuckets';
100 7 my $request = $s->request( $type );
101 7 my $response = $request->request();
102  
103 # Linode/Akamai E3 endpoints do not include the `xmlns` in
104 # ListAllMyBuckets, so use the localname to work with or
105 # without a declared XML namespace.
106 7 my $xml = $response->xml;
107 7 my @buckets = ();
108 7 foreach my $node ( $xml->getElementsByLocalName( 'Bucket' ) ) {
109 14 push @buckets,
110 AWS::S3::Bucket->new(
111 name => $node->getElementsByLocalName('Name')->string_value,
112 creation_date => $node->getElementsByLocalName('CreationDate')->string_value,
113 s3 => $s,
114 );
115 } # end foreach()
116  
117 7 $LOG->debug('Listed AWS buckets', { buckets => [map $_->name, @buckets] });
118 7 return @buckets;
119 } # end buckets()
120  
121 5 ▶sub bucket {
Subroutine bucket: called CC=2 SCAR=6.9
Pod documented
122 5 my ( $s, $name ) = @_;
123  
124 5 ▶ my ( $bucket ) = grep { $_->name eq $name } $s->buckets
Branch: 1 branch
BranchTrueFalseTotal
my($bucket) = grep({$_->name eq $name;} $s->buckets) or return 3 2 5
125 or return;
126 3 $bucket;
127 } # end bucket()
128  
129 3 ▶sub add_bucket {
Subroutine add_bucket: called CC=4 SCAR=13.9
Pod documented
130 3 my ( $s, %args ) = @_;
131  
132 3 my $type = 'CreateBucket';
133 my $request = $s->request(
134 $type,
135 bucket => $args{name},
136 (
137 $args{location} ? ( location => $args{location} )
138 3 ▶ : $s->region ? ( location => $s->region )
Branch: 2 branches
BranchTrueFalseTotal
$args{'location'} ? : 2 1 3
$s->region ? : 0 1 1
139 : ()
140 ),
141 );
142 3 my $response = $request->request();
143  
144 3 ▶ if ( my $msg = $response->friendly_error() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $msg = $response->friendly_error) 2 1 3
145 2 die $msg;
146 } # end if()
147  
148 1 return $s->bucket( $args{name} );
149 } # end add_bucket()
150  
151 6 __PACKAGE__->meta->make_immutable;
152  
153 __END__
« S3/Request/SetBucketPolicy.pm ↑ Summary S3/Roles/BucketAction.pm »