Twilio/Metadata.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 12 / 12 Conditioncond 100% 13 / 13 MC/DCmcdc 100% 7 / 7 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 100% 84 / 84 CC 12 SCAR 13.2
CC
12
Cov
100%
capture
7.0
get_header
4.0
__ANON__
2.0
CRAP 3.8
« Twilio/Jwt/Validation/ClientValidationJwt.pm ↑ Summary Twilio/Exceptions/TwilioServiceException.pm »
1 package Twilio::Metadata;
2  
3 3 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '2.001';
9  
10 # read returns a list, so its records are kept in an array reference.
11 3 my %RETURNS_LIST = (read => 1);
12  
13 19 ▶sub capture {
Subroutine capture: called CC=7 SCAR=19.5
Pod documented
14 19 my ($class, $resource, $operation, @arguments) = @_;
15  
16 19 ▶ if (!defined $operation || !length $operation) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $operation and length $operation) 2 17 19
Condition100%3/3
defined $operation and length $operation
!ll&&!rl&&r
1117
MC/DC100%2/2
defined $operation and length $operation
defined $operation length $operation
Truth table100%3/3
A and B
A= defined $operationB= length $operation
ABresult
0X0
100
111
17 2 croak 'with_metadata needs the name of an operation, such as fetch, create or read';
18 }
19 17 ▶ if ($operation =~ /\A_/ || $operation eq 'with_metadata' || !$resource->can($operation)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operation =~ /\A_/u or $operation eq "with_metadata" or not $resource->can($operation)) 3 14 17
Condition100%6/6
$operation =~ /\A_/u or $operation eq "with_metadata" or not $resource->can($operation)
l!l&&r!l&&!r
2114
$operation =~ /\A_/u or $operation eq "with_metadata"
l!l&&r!l&&!r
1115
MC/DC100%3/3
$operation =~ /\A_/u or $operation eq "with_metadata" or not $resource->can($operation)
$operation =~ /\A_/u $operation eq "with_metadata" not $resource->can($operation)
Truth table100%4/4
A or B or not(C)
A= $operation =~ /\A_/uB= $operation eq "with_metadata"C= not $resource->can($operation)
ABCresult
1XX1
01X1
0011
0000
20 3 croak 'with_metadata cannot call ' . ref($resource) . "->$operation";
21 }
22  
23 14 my $client = $resource->{version}->get_domain->get_client;
24 my ($data, @responses) = $client->capture_responses(
25 14 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
26 14 ▶ return $RETURNS_LIST{$operation}
Branch: 1 branch
BranchTrueFalseTotal
$RETURNS_LIST{$operation} ? : 2 12 14
27 ? [$resource->$operation(@arguments)]
28 : scalar $resource->$operation(@arguments);
29 }
30 14 );
31  
32 # The first answer, as in twilio-php: a read's first page, or the one answer of the others.
33 13 my ($response) = @responses;
34 13 ▶ croak "$operation made no request to Twilio, so there is no answer to describe" if !$response;
Branch: 1 branch
BranchTrueFalseTotal
unless $response 1 12 13
35 12 return $class->new($data, $response->get_status_code, $response->get_headers);
36 }
37  
38 14 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
39 14 my ($class, $data, $status_code, $headers) = @_;
40 14 ▶ return bless { data => $data, status_code => $status_code, headers => $headers // {} }, $class;
Condition100%2/2
$headers // {}
l!l
131
MC/DC100%1/1
$headers // {}
$headers
Truth table100%2/2
A
A= $headers
Aresult
11
00
41 }
42  
43 13 ▶sub get_data { return $_[0]{data} }
Subroutine get_data: called CC=1 SCAR=0.0
Pod documented
44 5 ▶sub get_status_code { return $_[0]{status_code} }
Subroutine get_status_code: called CC=1 SCAR=0.0
Pod documented
45 2 ▶sub get_headers { return $_[0]{headers} }
Subroutine get_headers: called CC=1 SCAR=0.0
Pod documented
46  
47 14 ▶sub get_header {
Subroutine get_header: called CC=4 SCAR=13.9
Pod documented
48 14 my ($self, $name) = @_;
49 14 ▶ my $wanted = lc($name // q{});
Condition100%2/2
$name // ""
l!l
131
MC/DC100%1/1
$name // ""
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
50 14 my ($key) = grep { lc eq $wanted } sort keys %{ $self->{headers} };
51 14 ▶ return if !defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 2 12 14
52  
53 # A header sent more than once comes as a list; RFC 9110 joins those with commas.
54 12 my $value = $self->{headers}{$key};
55 12 ▶ return ref $value eq 'ARRAY' ? join(', ', @{$value}) : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 1 11 12
56 }
57  
58 3 1;
59  
60 __END__
« Twilio/Jwt/Validation/ClientValidationJwt.pm ↑ Summary Twilio/Exceptions/TwilioServiceException.pm »