| 1 | package Amazon::API::Error; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use JSON qw( decode_json ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | __PACKAGE__->follow_best_practice; | |||||||||||||||||||||||||||
| 12 | 11 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||
| 13 | qw( | ||||||||||||||||||||||||||||
| 14 | action | ||||||||||||||||||||||||||||
| 15 | api | ||||||||||||||||||||||||||||
| 16 | content_type | ||||||||||||||||||||||||||||
| 17 | error | ||||||||||||||||||||||||||||
| 18 | message_raw | ||||||||||||||||||||||||||||
| 19 | response | ||||||||||||||||||||||||||||
| 20 | ) | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | use parent qw( Class::Accessor::Fast ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 11 | our $VERSION = '2.8.2'; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 11 | ▶ | use overload q("") => sub { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.8
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 28 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $err_prefix = sprintf 'API ERROR(%s): %s->%s', $self->get_error, $self->get_api, $self->get_action; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $response = $self->get_response; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||
| 35 | 0 | local $Data::Dumper::Pair = q{:}; | |||||||||||||||||||||||||||
| 36 | 0 | local $Data::Dumper::Useqq = 1; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $response_str = Dumper( ref $response ? $response : [$response] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | return sprintf "%s\n%s", $err_prefix, $response_str; | |||||||||||||||||||||||||||
| 41 | 11 | }; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ######################################################################## | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | ######################################################################## | ||||||||||||||||||||||||||||
| 46 | 0 | my ( $class, @options ) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $self = $class->SUPER::new(@options); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $self->_set_message; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | ############################################################### | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _set_message { | ||||||||||||||||||||||||||
|
Subroutine
_set_message: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 57 | ############################################################### | ||||||||||||||||||||||||||||
| 58 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $raw_message = $self->get_message_raw; | |||||||||||||||||||||||||||
| 61 | 0 | my $message; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($raw_message) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $self->get_content_type =~ /xml/xmsi ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 66 | 0 | require Amazon::API::XML::Simple; | |||||||||||||||||||||||||||
| 67 | 0 | $message = eval { return Amazon::API::XML::Simple::XMLin($raw_message); }; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | elsif ( $self->get_content_type =~ /json/xmsi ) { | ||||||||||||||||||||||||||||
| 70 | 0 | $message = eval { return decode_json($raw_message); }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # try a little harder... | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( !$message || $EVAL_ERROR ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $message or $Amazon::API::Error::EVAL_ERROR
MC/DC0%0/2
not $message or $Amazon::API::Error::EVAL_ERROR
not $message
$Amazon::API::Error::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not $messageB= $Amazon::API::Error::EVAL_ERROR
| |||||||||||||||||||||||||||||
| 75 | 0 | $message = eval { return decode_json($raw_message); }; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( !$message || $EVAL_ERROR ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $message or $Amazon::API::Error::EVAL_ERROR
MC/DC0%0/2
not $message or $Amazon::API::Error::EVAL_ERROR
not $message
$Amazon::API::Error::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not $messageB= $Amazon::API::Error::EVAL_ERROR
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( $raw_message =~ /^\s*\</xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | require Amazon::API::XML::Simple; | |||||||||||||||||||||||||||
| 80 | 0 | $message = eval { return Amazon::API::XML::Simple::XMLin($raw_message); }; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $message = $message || $raw_message; | ||||||||||||||||||||||||||
|
Condition0%0/3
$message || $raw_message
MC/DC0%0/2
$message || $raw_message
$message
$raw_message
Truth table0%0/3
A || B
A= $messageB= $raw_message
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $self->set_response($message); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return $message; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | ############################################################### | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub get_aws_api { | ||||||||||||||||||||||||||
|
Subroutine
get_aws_api: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | ############################################################### | ||||||||||||||||||||||||||||
| 97 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my $api = eval { return $self->get_api->get_api || ref( $self->get_api ); }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_api->get_api || ref $self->get_api
MC/DC0%0/2
$self->get_api->get_api || ref $self->get_api
$self->get_api->get_api
ref $self->get_api
Truth table0%0/3
A || B
A= $self->get_api->get_apiB= ref $self->get_api
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | return $api; | |||||||||||||||||||||||||||
| 102 | } ## end sub get_aws_api | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 11 | 1; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||