Twilio/Exceptions/TwilioServiceException.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 10 / 10 Conditioncond 64.7% 11 / 17 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 87.6% 92 / 105 CC 13 SCAR 12.6
CC
13
Cov
92%
_full_message
5.1
new
5.1
is_problem
5.0
CRAP 3.5
« Twilio/Metadata.pm ↑ Summary Twilio/Jwt/TaskRouter/CapabilityToken.pm »
1 package Twilio::Exceptions::TwilioServiceException;
2  
3 18 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # twilio-python and twilio-node have this class beside RestException. Here it inherits, as
7 # RestExceptionV1 does, so that code catching a RestException works with every API.
8 18 ▶use parent 'Twilio::Exceptions::RestException';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 18 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 18 our $VERSION = '2.001';
13  
14 18 my @REQUIRED_TEXT = qw(type title);
15 18 my @REQUIRED_NUMBERS = qw(status code);
16  
17 # The rule of twilio-node, stricter than twilio-python's: all four members, two of them numbers.
18 42 ▶sub is_problem {
Subroutine is_problem: called CC=5 SCAR=16.1
Pod documented
19 42 my ($class, $content) = @_;
20 42 ▶ return 0 if ref $content ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $content ne "HASH" 3 39 42
21 return 0
22 39 ▶ if grep { !defined $content->{$_} || ref $content->{$_} } @REQUIRED_TEXT, @REQUIRED_NUMBERS;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $content->{$_} or ref $content->{$_};} @REQUIRED_TEXT, @REQUIRED_NUMBERS 27 12 39
Condition100%3/3
!defined($content->{$_}) || ref $content->{$_}
l!l&&r!l&&!r
71184
MC/DC100%2/2
!defined($content->{$_}) || ref $content->{$_}
!defined($content->{$_}) ref $content->{$_}
Truth table100%3/3
not(A) || B
A= !defined($content->{$_})B= ref $content->{$_}
ABresult
1X1
011
000
23 12 ▶ return 0 if grep { !looks_like_number($content->{$_}) } @REQUIRED_NUMBERS;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not &looks_like_number($content->{$_});} @REQUIRED_NUMBERS 2 10 12
24 10 return 1;
25 }
26  
27 10 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
28 10 my ($class, $message, $problem, $status_code) = @_;
29 10 ▶ $problem //= {};
Condition50%1/2
$problem //= {}
l!l
100
MC/DC0%0/1
$problem //= {}
$problem
Truth table50%1/2
A
A= $problem
Aresult
11
00
30 10 ▶ my $errors = ref $problem->{errors} eq 'ARRAY' ? $problem->{errors} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $problem->{'errors'} eq 'ARRAY' ? : 8 2 10
31  
32 my $self = $class->SUPER::new(
33 _full_message($message, $problem, $errors), $problem->{code},
34 $status_code // $problem->{status}, $problem->{type}
35 10 ▶ );
Condition66%2/3
$status_code // $problem->{"status"}
l!l&&r!l&&!r
910
MC/DC0%0/2
$status_code // $problem->{"status"}
$status_code $problem->{"status"}
Truth table66%2/3
A // B
A= $status_codeB= $problem->{"status"}
ABresult
1X1
011
000
36 10 $self->{$_} = $problem->{$_} for qw(type title detail instance);
37 10 $self->{errors} = $errors;
38 10 return $self;
39 }
40  
41 1 ▶sub get_type { return $_[0]{type} }
Subroutine get_type: called CC=1 SCAR=0.0
Pod documented
42 1 ▶sub get_title { return $_[0]{title} }
Subroutine get_title: called CC=1 SCAR=0.0
Pod documented
43 2 ▶sub get_detail { return $_[0]{detail} }
Subroutine get_detail: called CC=1 SCAR=0.0
Pod documented
44 2 ▶sub get_instance { return $_[0]{instance} }
Subroutine get_instance: called CC=1 SCAR=0.0
Pod documented
45 4 ▶sub get_errors { return $_[0]{errors} }
Subroutine get_errors: called CC=1 SCAR=0.0
Pod documented
46  
47 10 ▶sub _full_message {
Subroutine _full_message: called CC=5 SCAR=16.3
48 10 my ($message, $problem, $errors) = @_;
49  
50 10 ▶ my $text = join ' - ', grep { defined && length } $problem->{title}, $problem->{detail};
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
2018
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
51 10 ▶ $message = join ': ', grep { defined && length } $message, $text;
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
0020
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
52  
53 17 my @fields = grep { length } map {
54 join ': ',
55 34 ▶ grep { defined && length }
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
4030
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
56 17 @{$_}{qw(pointer detail)}
57 }
58 10 grep { ref eq 'HASH' } @{$errors};
59 10 ▶ $message .= ' (' . join('; ', @fields) . ')' if @fields;
Branch: 1 branch
BranchTrueFalseTotal
if @fields 8 2 10
60 10 return $message;
61 }
62  
63 18 1;
64  
65 __END__
« Twilio/Metadata.pm ↑ Summary Twilio/Jwt/TaskRouter/CapabilityToken.pm »