| 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
| |||||||||||||||||||||||||||||
| 21 | return 0 | ||||||||||||||||||||||||||||
| 22 | 39 | ▶ | if grep { !defined $content->{$_} || ref $content->{$_} } @REQUIRED_TEXT, @REQUIRED_NUMBERS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
!defined($content->{$_}) || ref $content->{$_}
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->{$_}
| |||||||||||||||||||||||||||||
| 23 | 12 | ▶ | return 0 if grep { !looks_like_number($content->{$_}) } @REQUIRED_NUMBERS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 //= {}
MC/DC0%0/1
$problem //= {}
$problem
Truth table50%1/2
A
A= $problem
| |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | my $errors = ref $problem->{errors} eq 'ARRAY' ? $problem->{errors} : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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"}
MC/DC0%0/2
$status_code // $problem->{"status"}
$status_code
$problem->{"status"}
Truth table66%2/3
A // B
A= $status_codeB= $problem->{"status"}
| |||||||||||||||||||||||||||||
| 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 $_
MC/DC50%1/2
defined $_ && length $_
defined $_
length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 51 | 10 | ▶ | $message = join ': ', grep { defined && length } $message, $text; | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 17 | my @fields = grep { length } map { | |||||||||||||||||||||||||||
| 54 | join ': ', | ||||||||||||||||||||||||||||
| 55 | 34 | ▶ | grep { defined && length } | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && length $_
MC/DC50%1/2
defined $_ && length $_
defined $_
length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 56 | 17 | @{$_}{qw(pointer detail)} | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 10 | grep { ref eq 'HASH' } @{$errors}; | |||||||||||||||||||||||||||
| 59 | 10 | ▶ | $message .= ' (' . join('; ', @fields) . ')' if @fields; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 10 | return $message; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 18 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||