API/Botocore/Shape/Utils.pm

filter: Statementstmt 61.7% 134 / 217 Branchbran 44.5% 41 / 92 Conditioncond 28.1% 9 / 32 MC/DCmcdc 10.5% 2 / 19 Subroutinesub 73.6% 28 / 38 Podpod 0.0% 0 / 18 totaltotal 51.4% 214 / 416 CC 66 SCAR 38.3
CC
66
Cov
54%
flatten
182.0
param_n
132.0
parse_timestamp
72.0
CRAP 46.2
« API/Error.pm ↑ Summary API/EndpointResolver.pm »
1 package Amazon::API::Botocore::Shape::Utils;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 ▶use Amazon::API::Constants qw(:booleans :chars);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use List::Util qw( pairs any uniq );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use Scalar::Util qw(reftype blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use Time::Local qw(timegm);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 15 our @EXPORT_OK = qw(
20 $SHAPE_NAME_TEMPLATE
21 create_module_name
22 check_pattern
23 check_enum
24 _check
25 check_type
26 flatten
27 get_service_from_class
28 is_array
29 is_code
30 is_hash
31 is_regexp
32 is_scalar
33 param_n
34 parse_timestamp
35 query_param_n
36 register_service_shapes
37 require_class
38 require_shape
39 );
40  
41 15 our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
42  
43 15 Readonly::Scalar our $SHAPE_NAME_TEMPLATE => 'Amazon::API::Botocore::Shape::%s::%s';
44  
45 15 our $VERSION = '2.8.2'; ## no critic (RequireInterpolationOfMetachars)
46  
47 15 our %SERVICE_SHAPES; # cache keyed by service name
48  
49 ########################################################################
50 6 ▶sub register_service_shapes {
Subroutine register_service_shapes: called CC=1 SCAR=0.0
Pod undocumented
51 ########################################################################
52 6 my ( $service, $shapes ) = @_;
53  
54 6 $SERVICE_SHAPES{$service} = $shapes;
55  
56 6 return;
57 }
58  
59 ########################################################################
60 0 ▶sub is_scalar {
Subroutine is_scalar: not called CC=2 SCAR=17.9
Pod undocumented
61 ########################################################################
62 0 my ($obj) = @_;
63  
64 0 ▶ return ref $obj ? $FALSE : $TRUE;
Branch: 1 branch
BranchTrueFalseTotal
ref $obj ? : 0 0 0
65 }
66  
67 ########################################################################
68 0 ▶sub is_hash { return _is_type( @_, 'HASH' ); }
Subroutine is_hash: not called CC=1 SCAR=6.9
Pod undocumented
69 0 ▶sub is_array { return _is_type( @_, 'ARRAY' ); }
Subroutine is_array: not called CC=1 SCAR=6.9
Pod undocumented
70 0 ▶sub is_code { return _is_type( @_, 'CODE' ); }
Subroutine is_code: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶sub is_regexp { return _is_type( @_, 'REGEXP' ); }
Subroutine is_regexp: not called CC=1 SCAR=6.9
Pod undocumented
72 ########################################################################
73  
74 ########################################################################
75 0 ▶sub _is_type {
Subroutine _is_type: not called CC=3 SCAR=24.8
76 ########################################################################
77 0 my ( $obj, $type ) = @_;
78  
79 0 ▶ return ref $obj && reftype($obj) eq $type ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
ref $obj && builtin::reftype($obj) eq $type ? : 0 0 0
Condition0%0/3
ref $obj and builtin::reftype($obj) eq $type
!ll&&!rl&&r
000
MC/DC0%0/2
ref $obj and builtin::reftype($obj) eq $type
ref $obj builtin::reftype($obj) eq $type
Truth table0%0/3
A and B
A= ref $objB= builtin::reftype($obj) eq $type
ABresult
0X0
100
111
80 }
81  
82 ########################################################################
83 0 ▶sub create_module_name {
Subroutine create_module_name: not called CC=1 SCAR=6.9
Pod undocumented
84 ########################################################################
85 0 my ($service) = @_;
86  
87 0 require Amazon::API::Role::Botocore;
88  
89 0 my $package_name = Amazon::API::Role::Botocore->module_name($service);
90 0 $package_name =~ s/^.*::([^:]+)$/$1/xsm;
91  
92 0 return $package_name;
93 }
94  
95 ########################################################################
96 22 ▶sub require_class {
Subroutine require_class: called CC=2 SCAR=7.1
Pod undocumented
97 ########################################################################
98 22 my ($class) = @_;
99  
100 22 my $class_path = $class;
101  
102 22 $class_path =~ s/::/\//xsmg;
103  
104 0 my $retval = eval { require "$class_path.pm"; 1; };
105  
106 22 ▶ return $retval ? $INC{"$class_path.pm"} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$retval ? : 0 22 22
107 }
108  
109 ########################################################################
110 4 ▶sub get_service_from_class {
Subroutine get_service_from_class: called CC=3 SCAR=11.0
Pod undocumented
111 ########################################################################
112 4 my ($class) = @_;
113  
114 # return the canonical service name (e.g. CloudFront), we'll need this
115 # when creating the request class
116 4 ▶ my $name = ref $class ? ref $class : $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 3 1 4
117  
118 4 ▶ if ( $name =~ /::([^:]+)$/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /::([^:]+)$/msx) 4 0 4
119 4 $name = $1;
120 }
121  
122 4 return $name;
123 }
124  
125 ########################################################################
126 45 ▶sub require_shape {
Subroutine require_shape: called CC=5 SCAR=16.4
Pod undocumented
127 ########################################################################
128 45 my ( $shape, $service ) = @_;
129  
130 45 my $class = create_shape_name( $shape, $service );
131  
132 45 ▶ return $class if $class->isa('Amazon::API::Botocore::Shape');
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Amazon::API::Botocore::Shape") 23 22 45
133  
134 22 ▶ return $class if require_class($class);
Branch: 1 branch
BranchTrueFalseTotal
if require_class($class) 0 22 22
135  
136 22 ▶ my $shapes = $SERVICE_SHAPES{$service}
Branch: 1 branch
BranchTrueFalseTotal
my $shapes = $Amazon::API::Botocore::Shape::Utils::SERVICE_SHAPES{$service} or return 22 0 22
137 or return;
138  
139 22 ▶ my $shape_definition = $shapes->{$shape}
Branch: 1 branch
BranchTrueFalseTotal
my $shape_definition = $shapes->{$shape} or return 22 0 22
140 or return;
141  
142 22 _create_shape_class( $class, $shape_definition, $service );
143  
144 22 return $class;
145 }
146  
147 ########################################################################
148 22 ▶sub _create_shape_class {
Subroutine _create_shape_class: called CC=1 SCAR=0.1
149 ########################################################################
150  
151 22 my ( $class, $shape_definition, $service ) = @_;
152  
153 15 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
154  
155 22 push @{"${class}::ISA"}, 'Amazon::API::Botocore::Shape';
156  
157 22 ▶ *{"${class}::new"} = sub {
Subroutine __ANON__: called CC=5 SCAR=16.7
158 45 my ( $class, @args ) = @_;
159  
160 45 my %options = %{$shape_definition}; # copy - do not mutate the cache
161 45 my $value;
162  
163 45 ▶ if ( @args && !$args[0] && $options{type} eq 'structure' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args and not $args[0] and $options{'type'} eq 'structure') { } 0 45 45
elsif (@args) { } 43 2 45
Condition50%3/6
@args and not $args[0] and $options{"type"} eq "structure"
!ll&&!rl&&r
4500
@args and not $args[0]
!ll&&!rl&&r
2430
MC/DC0%0/3
@args and not $args[0] and $options{"type"} eq "structure"
@args not $args[0] $options{"type"} eq "structure"
Truth table50%2/4
A and not(B) and C
A= @argsB= not $args[0]C= $options{"type"} eq "structure"
ABCresult
0XX0
10X0
1100
1111
164 0 $value = {};
165 }
166 elsif (@args) {
167 43 $value = $args[0];
168 }
169  
170 45 $options{_value} = $value;
171 45 $options{service} = $service;
172  
173 45 return $class->Amazon::API::Botocore::Shape::new( \%options );
174 22 };
175  
176 22 return;
177 }
178  
179 ########################################################################
180 24 ▶sub check_pattern {
Subroutine check_pattern: called CC=3 SCAR=11.1
Pod undocumented
181 ########################################################################
182 24 my ( $value, $pattern ) = @_;
183  
184 24 ▶ return $TRUE if !$pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $pattern 21 3 24
185  
186 ## no critic
187  
188 3 eval {
189 15 ▶ use warnings FATAL => qw( regexp );
Subroutine BEGIN: called CC=1 SCAR=0.0
190  
191 3 qr/$pattern/;
192 };
193  
194 3 ▶ if ( !$EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Amazon::API::Botocore::Shape::Utils::EVAL_ERROR) 3 0 3
195 3 my $matched = $value =~ /$pattern/sm;
196 3 return _check( $matched, "value must match pattern [$pattern]" );
197 }
198  
199 0 return $TRUE;
200 }
201  
202 ########################################################################
203 23 ▶sub check_enum {
Subroutine check_enum: called CC=3 SCAR=11.0
Pod undocumented
204 ########################################################################
205 23 my ( $value, $enum ) = @_;
206  
207 return $TRUE
208 23 ▶ if !$enum || !@{$enum}; # no constraint present - nothing to check
Branch: 1 branch
BranchTrueFalseTotal
unless $enum and @{$enum;} 19 4 23
Condition66%2/3
$enum and @{$enum;}
!ll&&!rl&&r
1904
MC/DC50%1/2
$enum and @{$enum;}
$enum @{$enum;}
Truth table66%2/3
A and B
A= $enumB= @{$enum;}
ABresult
0X0
100
111
209  
210 return _check(
211 4 ▶ ( any { $_ eq $value } @{$enum} ),
Subroutine __ANON__: called CC=1 SCAR=0.0
212 sprintf q{value [%s] is not one of the allowed values: %s},
213 4 $value, join q{, }, @{$enum}
214 );
215 }
216  
217 ########################################################################
218 58 ▶sub _check {
Subroutine _check: called CC=5 SCAR=16.1
219 ########################################################################
220 58 my ( $ok, $message ) = @_;
221  
222 58 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $ok 48 10 58
223 if $ok;
224  
225 10 ▶ my $mode = $Amazon::API::VALIDATE_MODE // q{strict};
Condition50%1/2
$Amazon::API::VALIDATE_MODE // "strict"
l!l
100
MC/DC0%0/1
$Amazon::API::VALIDATE_MODE // "strict"
$Amazon::API::VALIDATE_MODE
Truth table50%1/2
A
A= $Amazon::API::VALIDATE_MODE
Aresult
11
00
226  
227 10 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "off" 4 6 10
228 if $mode eq q{off};
229  
230 6 ▶ if ( $mode eq q{warn} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "warn") 1 5 6
231 1 carp "$message\n";
232 1 return $TRUE;
233 }
234  
235 5 croak sprintf qq{%s\nIf the AWS API has changed since this client's Botocore }
236 . qq{metadata was generated, set }
237 . qq{\$Amazon::API::VALIDATE_MODE to 'warn' or 'off' }
238 . qq{(or rebuild the metadata).\n}, $message;
239 }
240  
241 ########################################################################
242 63 ▶sub check_type {
Subroutine check_type: called CC=3 SCAR=11.0
Pod undocumented
243 ########################################################################
244 63 my ( $required_type, $type ) = @_;
245  
246 63 ▶ return any { $type eq $_ } @{$required_type}
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if ref $required_type 1 62 63
247 if ref $required_type;
248  
249 62 ▶ $type ||= 'SCALAR';
Condition50%1/2
$type ||= "SCALAR"
l!l
620
MC/DC0%0/1
$type ||= "SCALAR"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
250  
251 62 return $required_type eq $type;
252 }
253  
254 ########################################################################
255 # flatten('Tag', $tag_list), flatten({ Tag => $tag_list })
256 ########################################################################
257 0 ▶sub flatten {
Subroutine flatten: not called CC=13 SCAR=52.0
Pod undocumented
258 ########################################################################
259 0 my (@args) = @_;
260  
261 0 my ( $name, $list ) = @args;
262  
263 # flattening an array implies creating a hash from an array of
264 # hashes?
265 0 ▶ if ( ref $list && reftype($list) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $list and builtin::reftype($list) eq "ARRAY") 0 0 0
Condition0%0/3
ref $list and builtin::reftype($list) eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $list and builtin::reftype($list) eq "ARRAY"
ref $list builtin::reftype($list) eq "ARRAY"
Truth table0%0/3
A and B
A= ref $listB= builtin::reftype($list) eq "ARRAY"
ABresult
0X0
100
111
266 0 my $map = {};
267  
268 0 foreach my $p ( @{$list} ) {
269 0 my ( $k, $v ) = %{$p};
270 0 $map->{$k} = $v;
271 }
272  
273 0 return $map;
274 }
275  
276 # already flattened?
277 0 ▶ if ( ref $name && ref $name eq 'ARRAY' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $name and ref $name eq 'ARRAY') { } 0 0 0
elsif (ref $name) { } 0 0 0
elsif (not ref $list or builtin::reftype($list) ne 'ARRAY') { } 0 0 0
Condition0%0/3
ref $name and ref $name eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $name and ref $name eq "ARRAY"
ref $name ref $name eq "ARRAY"
Truth table0%0/3
A and B
A= ref $nameB= ref $name eq "ARRAY"
ABresult
0X0
100
111
278 0 return $name;
279 }
280 elsif ( ref $name ) {
281 0 ( $name, $list ) = %{$name};
282 }
283 ▶ elsif ( !ref $list || reftype($list) ne 'ARRAY' ) {
Condition0%0/3
not ref $list or builtin::reftype($list) ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $list or builtin::reftype($list) ne "ARRAY"
not ref $list builtin::reftype($list) ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not ref $listB= builtin::reftype($list) ne "ARRAY"
ABresult
1X1
011
000
284 0 die sprintf "I don't know how to serialize %\n", Dumper( \@args );
285 }
286  
287 0 my @output;
288  
289 0 my $idx = 1;
290  
291 0 foreach my $elem ( @{$list} ) {
292  
293 0 ▶ if ( ref $elem && reftype($elem) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elem and builtin::reftype($elem) eq 'HASH') { } 0 0 0
Condition0%0/3
ref $elem and builtin::reftype($elem) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $elem and builtin::reftype($elem) eq "HASH"
ref $elem builtin::reftype($elem) eq "HASH"
Truth table0%0/3
A and B
A= ref $elemB= builtin::reftype($elem) eq "HASH"
ABresult
0X0
100
111
294 0 my @kv = %{$elem};
295  
296 0 foreach my $p ( pairs @kv ) {
297 0 my ( $key, $value ) = @{$p};
298 0 $key = sprintf '%s.%d.%s', $name, $idx, $key;
299  
300 0 push @output, { $key => $value };
301 }
302 }
303 else {
304 0 my $key = sprintf '%s.%d', $name, $idx;
305  
306 0 push @output, { $key => $elem };
307 }
308  
309 0 $idx++;
310 }
311  
312 0 return \@output;
313 }
314  
315 ########################################################################
316 # param_n() is a rather naive attempt to implement a way to create the
317 # "param n" notation used by some Amazon APIs (most notably APIs using
318 # a "map" shape and expecting a query string - e.g. SQS?)
319 #
320 # Note that param_n() and flatten() are related but produce different
321 # output and accept slightly different input. Whereas param_n() can be
322 # sent an object that contains some parameters that might not be
323 # serialized in the param_n() notation, flatten() input should only be
324 # an object that will be serialized in an intermediate param_n() format
325 # suitable for create_urlencoded_content().
326 #
327 # Both must be passed a valid request. A "valid" request is one in
328 # which the parameters represent the serialized version of the "map"
329 # parameter shape. For example to send multiple tags to one of the
330 # APIs that use the param_n notation you would pass an object that
331 # looks like this:
332 #
333 # my $tags = Tag => [ { Key => 'Name', Value => 'foo'},
334 # { Key => 'Env', Value => 'dev }
335 # ];
336 #
337 # The finalize() method of botocore request objects
338 # (Amazon::API::Botocore::Shape) will produce this exact serialized
339 # representation when passed an object that looks like this:
340 #
341 # my $tags = Tag => [ { 'Name' => 'foo' },
342 # { 'Env' => 'dev' },
343 # ];
344 #
345 # It knows knows how to create the former structure by consulting the
346 # botocore metadata for the TagMap "map" type.
347 #
348 # param_n() was written prior to the use of botocore metadata and
349 # assumes the the object being passed was hand rolled by someone with
350 # the knowledge of the required finalized map object.
351 #
352 # flatten($tags) != param_n($tags)
353 #
354 # ...however...surprisingly....
355 #
356 # create_urlencode_content(flatten($tags)) == create_urlencode_content(param_n($tags))
357 #
358 # f(x) <> g(x), but h(f(x)) == h(g(x))
359 #
360 # In other words, create_urlencoded_content() in an isomorphic
361 # transformation function.
362 #
363 ########################################################################
364 0 ▶sub param_n {
Subroutine param_n: not called CC=11 SCAR=48.8
Pod undocumented
365 ########################################################################
366 0 my ( $message, $prefix, $idx ) = @_;
367  
368 0 ▶ if ( !defined $idx ) { # first call, check args
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $idx) 0 0 0
369 0 ▶ croak 'message argument must be reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $message 0 0 0
370 if !ref $message;
371 }
372  
373 0 my @param_n;
374  
375 0 ▶ if ( ref $message ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $message) { } 0 0 0
376 0 ▶ if ( reftype($message) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($message) eq 'HASH') { } 0 0 0
377 0 foreach my $k ( keys %{$message} ) {
378 0 ▶ push @param_n, param_n( $message->{$k}, $prefix ? "$prefix.$k" : $k, $idx // 0 );
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
Condition0%0/2
$idx // 0
l!l
00
MC/DC0%0/1
$idx // 0
$idx
Truth table0%0/2
A
A= $idx
Aresult
11
00
379 }
380 }
381 else {
382 0 $idx = 1;
383 0 foreach my $e ( @{$message} ) {
384 0 ▶ push @param_n, param_n( $e, $prefix ? "$prefix.$idx" : $EMPTY, $idx++ );
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
385 }
386 }
387 }
388 else {
389 return @param_n
390 0 ▶ if !defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 0 0
391  
392 0 return "$prefix=$message";
393 }
394  
395 0 return @param_n;
396 } ## end sub param_n
397  
398 ########################################################################
399 16 ▶sub query_param_n {
Subroutine query_param_n: called CC=13 SCAR=25.7
Pod undocumented
400 ########################################################################
401 16 my ( $message, $prefix, $idx ) = @_;
402  
403 16 ▶ if ( !defined $idx ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $idx) 6 10 16
404 6 ▶ croak 'message argument must be reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $message 0 6 6
405 if !ref $message;
406 }
407  
408 16 ▶ if ( JSON::PP::is_bool($message) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (JSON::PP::is_bool($message)) 2 14 16
409 2 ▶ return sprintf '%s=%s', $prefix, $message ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$message ? : 1 1 2
410 }
411  
412 14 my @param_n;
413  
414 14 ▶ if ( ref $message ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $message) { } 8 6 14
415 8 ▶ if ( reftype($message) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($message) eq 'HASH') { } 7 1 8
416 7 foreach my $k ( keys %{$message} ) {
417 9 ▶ push @param_n, query_param_n( $message->{$k}, $prefix ? "$prefix.$k" : $k, $idx // 0 );
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 7 2 9
Condition100%2/2
$idx // 0
l!l
54
MC/DC100%1/1
$idx // 0
$idx
Truth table100%2/2
A
A= $idx
Aresult
11
00
418 }
419 }
420 else {
421 1 $idx = 1;
422 1 foreach my $e ( @{$message} ) {
423 1 ▶ my $member_prefix = $prefix ? "$prefix.member.$idx" : "member.$idx";
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 1 0 1
424 1 push @param_n, query_param_n( $e, $member_prefix, $idx++ );
425 }
426 }
427 }
428 else {
429 return @param_n
430 6 ▶ if !defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 1 5 6
431  
432 5 return "$prefix=$message";
433 }
434  
435 8 return @param_n;
436 }
437  
438 ########################################################################
439 45 ▶sub create_shape_name {
Subroutine create_shape_name: called CC=1 SCAR=0.0
Pod undocumented
440 ########################################################################
441 45 my ( $name, $service ) = @_;
442  
443 45 return sprintf $SHAPE_NAME_TEMPLATE, $service, $name;
444 }
445  
446 ########################################################################
447 0 ▶sub parse_timestamp {
Subroutine parse_timestamp: not called CC=8 SCAR=42.8
Pod undocumented
448 ########################################################################
449 0 my ($value) = @_;
450  
451 return
452 0 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
453  
454 0 ▶ return $value + 0
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^-?\d+(?:\.\d+)?$/msx 0 0 0
455 if $value =~ /^-?\d+(?:\.\d+)?$/xsm;
456  
457 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ / ^ (\d{4})-(\d{2})-(\d{2}) T (\d{2}):(\d{2}):(\d{2}) (?:\.(\d+))? (Z|[+-]\d{2}:\d{2}) $ /msx) 0 0 0
458 $value =~ m{
459 ^
460 (\d{4})-(\d{2})-(\d{2})
461 T
462 (\d{2}):(\d{2}):(\d{2})
463 (?:\.(\d+))?
464 (Z|[+-]\d{2}:\d{2})
465 $
466 }xsm
467 ) {
468 0 my ( $year, $month, $day, $hour, $minute, $second, $fraction, $zone ) = ( $1, $2, $3, $4, $5, $6, $7, $8 );
469  
470 0 my $epoch = timegm( $second, $minute, $hour, $day, $month - 1, $year, );
471  
472 0 ▶ if ( $zone ne 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone ne "Z") 0 0 0
473 0 my ( $sign, $zone_hour, $zone_minute ) = $zone =~ /^([+-])(\d{2}):(\d{2})$/xsm;
474  
475 0 my $offset = ( $zone_hour * 3600 ) + ( $zone_minute * 60 );
476  
477 0 ▶ if ( $sign eq q{+} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sign eq '+') { } 0 0 0
478 0 $epoch -= $offset;
479 }
480 else {
481 0 $epoch += $offset;
482 }
483 }
484  
485 0 ▶ if ( defined $fraction ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fraction) 0 0 0
486 0 $epoch += sprintf '0.%s', $fraction;
487 }
488  
489 0 return $epoch;
490 }
491  
492 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ / ^ \w{3},\s+ (\d{2})\s+ (\w{3})\s+ (\d{4})\s+ (\d{2}):(\d{2}):(\d{2})\s+ GMT $ /msx) 0 0 0
493 $value =~ m{
494 ^
495 \w{3},\s+
496 (\d{2})\s+
497 (\w{3})\s+
498 (\d{4})\s+
499 (\d{2}):(\d{2}):(\d{2})\s+
500 GMT
501 $
502 }xsm
503 ) {
504 0 my ( $day, $month_name, $year, $hour, $minute, $second ) = ( $1, $2, $3, $4, $5, $6 );
505  
506 0 my %months = (
507 Jan => 0,
508 Feb => 1,
509 Mar => 2,
510 Apr => 3,
511 May => 4,
512 Jun => 5,
513 Jul => 6,
514 Aug => 7,
515 Sep => 8,
516 Oct => 9,
517 Nov => 10,
518 Dec => 11,
519 );
520  
521 0 return timegm( $second, $minute, $hour, $day, $months{$month_name}, $year, );
522 }
523  
524 0 return $value;
525 }
526  
527 15 1;
« API/Error.pm ↑ Summary API/EndpointResolver.pm »