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 SCAR 22.4
CC
9
Cov
82%
_build_signed_request
7.0
__ANON__
6.0
__ANON__
2.0
CRAP 9.4
« Net/Amazon/S3/HTTPRequest.pm ↑ Summary Net/Amazon/S3/Role/Bucket.pm »
1 package Net::Amazon::S3::Request;
2 99 $Net::Amazon::S3::Request::VERSION = '0.99';
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-northeast-1',
18 'ap-northeast-2',
19 'ap-northeast-3',
20 'ap-south-1',
21 'ap-southeast-1',
22 'ap-southeast-2',
23 'ca-central-1',
24 'cn-north-1',
25 'cn-northwest-1',
26 'EU',
27 'eu-central-1',
28 'eu-north-1',
29 'eu-south-1',
30 'eu-west-1',
31 'eu-west-2',
32 'eu-west-3',
33 'me-south-1',
34 'sa-east-1',
35 'us-east-1',
36 'us-east-2',
37 'us-gov-east-1',
38 'us-gov-west-1',
39 'us-west-1',
40 'us-west-2',
41 ];
42  
43 99 subtype 'MaybeLocationConstraint'
44 => as 'Maybe[LocationConstraint]'
45 ;
46  
47 # maintain backward compatiblity with 'US' and 'EU' values
48 99 my %location_constraint_alias = (
49 US => 'us-east-1',
50 EU => 'eu-west-1',
51 );
52  
53 99 enum 'LocationConstraintAlias' => [ keys %location_constraint_alias ];
54  
55 coerce 'LocationConstraint'
56 => from 'LocationConstraintAlias'
57 0 ▶ => via { $location_constraint_alias{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 99 ;
59  
60 coerce 'MaybeLocationConstraint'
61 => from 'LocationConstraintAlias'
62 0 ▶ => via { $location_constraint_alias{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 99 ;
64  
65 # To comply with Amazon S3 requirements, bucket names must:
66 # Contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)
67 # Start with a number or letter
68 # Be between 3 and 255 characters long
69 # Not be in an IP address style (e.g., "192.168.5.4")
70  
71 subtype 'BucketName1' => as 'Str' => where {
72 0 ▶ $_ =~ /^[a-zA-Z0-9._-]+$/;
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 } => message {
74 0 ▶ "Bucket name ($_) must contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)";
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 99 };
76  
77 subtype 'BucketName2' => as 'BucketName1' => where {
78 0 ▶ $_ =~ /^[a-zA-Z0-9]/;
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 } => message {
80 0 ▶ "Bucket name ($_) must start with a number or letter";
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 99 };
82  
83 subtype 'BucketName3' => as 'BucketName2' => where {
84 0 ▶ length($_) >= 3 && length($_) <= 255;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
length $_ >= 3 and length $_ <= 255 0 0 0
85 } => message {
86 0 ▶ "Bucket name ($_) must be between 3 and 255 characters long";
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 99 };
88  
89 subtype 'BucketName' => as 'BucketName3' => where {
90 0 ▶ $_ !~ /^$RE{net}{IPv4}$/;
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 } => message {
92 0 ▶ "Bucket name ($_) must not be in an IP address style (e.g., '192.168.5.4')";
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 99 };
94  
95 99 has 's3' => ( is => 'ro', isa => 'Net::Amazon::S3', required => 1 );
96  
97 99 has '_http_request_content' => (
98 is => 'ro',
99 init_arg => undef,
100 isa => 'Maybe[Str]',
101 lazy => 1,
102 builder => '_request_content',
103 );
104  
105 99 __PACKAGE__->meta->make_immutable;
106  
107 sub _request_content {
108 139 ▶ '';
Subroutine _request_content: called CC=1 SCAR=0.0
109 }
110  
111 sub _request_path {
112 430 ▶ '';
Subroutine _request_path: called CC=1 SCAR=0.0
113 }
114  
115 ▶sub _request_headers {
Subroutine _request_headers: called CC=1 SCAR=0.0
116 }
117  
118 ▶sub _request_query_action {
Subroutine _request_query_action: called CC=1 SCAR=0.0
119 }
120  
121 ▶sub _request_query_params {
Subroutine _request_query_params: called CC=1 SCAR=0.0
122 }
123  
124 sub _request_query_string {
125 416 ▶ my ($self) = @_;
Subroutine _request_query_string: called CC=2 SCAR=6.9
126  
127 416 my %query_params = $self->_request_query_params;
128  
129 416 my @parts = (
130 ($self->_request_query_action) x!! $self->_request_query_action,
131 74 map "$_=${\ $self->s3->_urlencode( $query_params{$_} ) }", sort keys %query_params,
132 );
133  
134 416 ▶ return '' unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 184 232 416
135 232 return '?' . join '&', @parts;
136 }
137  
138 sub _http_request_path {
139 416 ▶ my ($self) = @_;
Subroutine _http_request_path: called CC=1 SCAR=0.0
140  
141 416 return $self->_request_path . $self->_request_query_string;
142 }
143  
144 sub _http_request_headers {
145 430 ▶ my ($self) = @_;
Subroutine _http_request_headers: called CC=1 SCAR=0.0
146  
147 430 return +{ $self->_request_headers };
148 }
149  
150 sub _build_signed_request {
151 430 ▶ my ($self, %params) = @_;
Subroutine _build_signed_request: called CC=7 SCAR=19.5
152  
153 430 ▶ $params{path} = $self->_http_request_path unless exists $params{path};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"path"} 416 14 430
154 430 ▶ $params{method} = $self->_http_request_method unless exists $params{method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"method"} 424 6 430
155 430 ▶ $params{headers} = $self->_http_request_headers unless exists $params{headers};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"headers"} 430 0 430
156 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
157  
158 # Although Amazon's Signature 4 test suite explicitely handles // it appears
159 # it's inconsistent with their implementation so removing it here
160 430 $params{path} =~ s{//+}{/}g;
161  
162 430 ▶ return Net::Amazon::S3::HTTPRequest->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->can('bucket') ? : 417 13 430
163 %params,
164 s3 => $self->s3,
165 $self->can( 'bucket' ) ? (bucket => $self->bucket) : (),
166 );
167 }
168  
169 sub _build_http_request {
170 210 ▶ my ($self, %params) = @_;
Subroutine _build_http_request: called CC=1 SCAR=0.0
171  
172 210 return $self->_build_signed_request( %params )->http_request;
173 }
174  
175 sub http_request {
176 294 ▶ my $self = shift;
Subroutine http_request: called CC=1 SCAR=0.0
Pod undocumented
177  
178 294 return $self->_build_http_request;
179 }
180  
181 99 1;
182  
183 __END__
184  
185 =pod
186  
187 =encoding UTF-8
188  
189 =head1 NAME
190  
191 Net::Amazon::S3::Request - Base class for request objects
192  
193 =head1 VERSION
194  
195 version 0.99
196  
197 =head1 SYNOPSIS
198  
199 # do not instantiate directly
200  
201 =head1 DESCRIPTION
202  
203 This module is a base class for all the Net::Amazon::S3::Request::*
204 classes.
205  
206 =head1 AUTHOR
207  
208 Branislav Zahradník <barney@cpan.org>
209  
210 =head1 COPYRIGHT AND LICENSE
211  
212 This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.
213  
214 This is free software; you can redistribute it and/or modify it under
215 the same terms as the Perl 5 programming language system itself.
216  
217 =cut
« Net/Amazon/S3/HTTPRequest.pm ↑ Summary Net/Amazon/S3/Role/Bucket.pm »