Net/Amazon/S3/Request.pm

filter: Statementstmt 84.1% 53 / 63 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 61.5% 16 / 26 Podpod 0.0% 0 / 1 totaltotal 76.1% 83 / 109 CC 9 SCAR 10.5
CC
9
Cov
82%
_build_signed_request
7.0
__ANON__
6.0
__ANON__
2.0
CRAP 2.9
« Net/Amazon/S3/Error/Handler/Legacy.pm ↑ Summary Net/Amazon/S3/Role/ACL.pm »
1 package Net::Amazon::S3::Request;
2 99 $Net::Amazon::S3::Request::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 Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 99 ▶use Regexp::Common qw /net/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Base class for request objects
9  
10 99 ▶use Net::Amazon::S3::Constraint::ACL::Canned;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 99 enum 'LocationConstraint' => [
13 # https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
14 # https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#API_CreateBucket_RequestSyntax
15 'af-south-1',
16 'ap-east-1',
17 'ap-east-2',
18 'ap-northeast-1',
19 'ap-northeast-2',
20 'ap-northeast-3',
21 'ap-south-1',
22 'ap-south-2',
23 'ap-southeast-1',
24 'ap-southeast-2',
25 'ap-southeast-3',
26 'ap-southeast-4',
27 'ap-southeast-5',
28 'ap-southeast-7',
29 'ca-central-1',
30 'ca-west-1',
31 'cn-north-1',
32 'cn-northwest-1',
33 'EU',
34 'eu-central-1',
35 'eu-central-2',
36 'eu-north-1',
37 'eu-south-1',
38 'eu-south-2',
39 'eu-west-1',
40 'eu-west-2',
41 'eu-west-3',
42 'il-central-1',
43 'me-central-1',
44 'me-south-1',
45 'mx-central-1',
46 'sa-east-1',
47 'us-east-1',
48 'us-east-2',
49 'us-gov-east-1',
50 'us-gov-west-1',
51 'us-west-1',
52 'us-west-2',
53 ];
54  
55 99 subtype 'MaybeLocationConstraint'
56 => as 'Maybe[LocationConstraint]'
57 ;
58  
59 # maintain backward compatiblity with 'US' and 'EU' values
60 99 my %location_constraint_alias = (
61 US => 'us-east-1',
62 EU => 'eu-west-1',
63 );
64  
65 99 enum 'LocationConstraintAlias' => [ keys %location_constraint_alias ];
66  
67 coerce 'LocationConstraint'
68 => from 'LocationConstraintAlias'
69 0 ▶ => via { $location_constraint_alias{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 99 ;
71  
72 coerce 'MaybeLocationConstraint'
73 => from 'LocationConstraintAlias'
74 0 ▶ => via { $location_constraint_alias{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 99 ;
76  
77 # To comply with Amazon S3 requirements, bucket names must:
78 # Contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)
79 # Start with a number or letter
80 # Be between 3 and 255 characters long
81 # Not be in an IP address style (e.g., "192.168.5.4")
82  
83 0 ▶subtype 'BucketName1' => as 'Str' => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 $_ =~ /^[a-zA-Z0-9._-]+$/;
85 0 ▶} => message {
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 "Bucket name ($_) must contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)";
87 99 };
88  
89 0 ▶subtype 'BucketName2' => as 'BucketName1' => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 $_ =~ /^[a-zA-Z0-9]/;
91 0 ▶} => message {
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 "Bucket name ($_) must start with a number or letter";
93 99 };
94  
95 0 ▶subtype 'BucketName3' => as 'BucketName2' => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
96 0 ▶ length($_) >= 3 && length($_) <= 255;
Branch: 1 branch
BranchTrueFalseTotal
length $_ >= 3 and length $_ <= 255 0 0 0
97 0 ▶} => message {
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 "Bucket name ($_) must be between 3 and 255 characters long";
99 99 };
100  
101 0 ▶subtype 'BucketName' => as 'BucketName3' => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 $_ !~ /^$RE{net}{IPv4}$/;
103 0 ▶} => message {
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 "Bucket name ($_) must not be in an IP address style (e.g., '192.168.5.4')";
105 99 };
106  
107 99 has 's3' => ( is => 'ro', isa => 'Net::Amazon::S3', required => 1 );
108  
109 99 has '_http_request_content' => (
110 is => 'ro',
111 init_arg => undef,
112 isa => 'Maybe[Str]',
113 lazy => 1,
114 builder => '_request_content',
115 );
116  
117 99 __PACKAGE__->meta->make_immutable;
118  
119 139 ▶sub _request_content {
Subroutine _request_content: called CC=1 SCAR=0.0
120 139 '';
121 }
122  
123 430 ▶sub _request_path {
Subroutine _request_path: called CC=1 SCAR=0.0
124 430 '';
125 }
126  
127 358 ▶sub _request_headers {
Subroutine _request_headers: called CC=1 SCAR=0.0
128 }
129  
130 464 ▶sub _request_query_action {
Subroutine _request_query_action: called CC=1 SCAR=0.0
131 }
132  
133 416 ▶sub _request_query_params {
Subroutine _request_query_params: called CC=1 SCAR=0.0
134 }
135  
136 416 ▶sub _request_query_string {
Subroutine _request_query_string: called CC=2 SCAR=6.9
137 416 my ($self) = @_;
138  
139 416 my %query_params = $self->_request_query_params;
140  
141 416 my @parts = (
142 ($self->_request_query_action) x!! $self->_request_query_action,
143 74 map "$_=${\ $self->s3->_urlencode( $query_params{$_} ) }", sort keys %query_params,
144 );
145  
146 416 ▶ return '' unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 184 232 416
147 232 return '?' . join '&', @parts;
148 }
149  
150 416 ▶sub _http_request_path {
Subroutine _http_request_path: called CC=1 SCAR=0.0
151 416 my ($self) = @_;
152  
153 416 return $self->_request_path . $self->_request_query_string;
154 }
155  
156 430 ▶sub _http_request_headers {
Subroutine _http_request_headers: called CC=1 SCAR=0.0
157 430 my ($self) = @_;
158  
159 430 return +{ $self->_request_headers };
160 }
161  
162 430 ▶sub _build_signed_request {
Subroutine _build_signed_request: called CC=7 SCAR=19.5
163 430 my ($self, %params) = @_;
164  
165 430 ▶ $params{path} = $self->_http_request_path unless exists $params{path};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"path"} 416 14 430
166 430 ▶ $params{method} = $self->_http_request_method unless exists $params{method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"method"} 424 6 430
167 430 ▶ $params{headers} = $self->_http_request_headers unless exists $params{headers};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"headers"} 430 0 430
168 430 ▶ $params{content} = $self->_http_request_content unless exists $params{content} or ! defined $self->_http_request_content;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"content"} or not defined $self->_http_request_content 389 41 430
Condition66%2/3
exists $params{"content"} or not defined $self->_http_request_content
l!l&&r!l&&!r
410389
MC/DC50%1/2
exists $params{"content"} or not defined $self->_http_request_content
exists $params{"content"} not defined $self->_http_request_content
Truth table66%2/3
A or not(B)
A= exists $params{"content"}B= not defined $self->_http_request_content
ABresult
1X1
011
000
169  
170 # Although Amazon's Signature 4 test suite explicitely handles // it appears
171 # it's inconsistent with their implementation so removing it here
172 430 $params{path} =~ s{//+}{/}g;
173  
174 430 ▶ return Net::Amazon::S3::HTTPRequest->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->can('bucket') ? : 417 13 430
175 %params,
176 s3 => $self->s3,
177 $self->can( 'bucket' ) ? (bucket => $self->bucket) : (),
178 );
179 }
180  
181 210 ▶sub _build_http_request {
Subroutine _build_http_request: called CC=1 SCAR=0.0
182 210 my ($self, %params) = @_;
183  
184 210 return $self->_build_signed_request( %params )->http_request;
185 }
186  
187 294 ▶sub http_request {
Subroutine http_request: called CC=1 SCAR=0.0
Pod undocumented
188 294 my $self = shift;
189  
190 294 return $self->_build_http_request;
191 }
192  
193 99 1;
194  
195 __END__
« Net/Amazon/S3/Error/Handler/Legacy.pm ↑ Summary Net/Amazon/S3/Role/ACL.pm »