« lib/auto/share/dist/Amazon-SQS-Client/CreateQueue.pm
↑ Summary
lib/auto/share/dist/Amazon-SQS-Client/ChangeMessageVisibility.pm »
| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | package Amazon::SQS::QueueHandler; | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Amazon::Credentials; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Amazon::SQS::Model::DeleteMessageRequest; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Amazon::SQS::Model::ReceiveMessageRequest; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Amazon::SQS::Client; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use CGI::Simple; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use List::Util qw(none max); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 2 | __PACKAGE__->follow_best_practice; | |||||||||||||||||||||||||||||||||
| 18 | 2 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||
| 19 | qw( | ||||||||||||||||||||||||||||||||||
| 20 | config | ||||||||||||||||||||||||||||||||||
| 21 | create_queue | ||||||||||||||||||||||||||||||||||
| 22 | credentials | ||||||||||||||||||||||||||||||||||
| 23 | endpoint_url | ||||||||||||||||||||||||||||||||||
| 24 | logger | ||||||||||||||||||||||||||||||||||
| 25 | max_error_retry | ||||||||||||||||||||||||||||||||||
| 26 | message | ||||||||||||||||||||||||||||||||||
| 27 | message_id | ||||||||||||||||||||||||||||||||||
| 28 | message_type | ||||||||||||||||||||||||||||||||||
| 29 | message_body | ||||||||||||||||||||||||||||||||||
| 30 | raw_message | ||||||||||||||||||||||||||||||||||
| 31 | receipt_handle | ||||||||||||||||||||||||||||||||||
| 32 | request | ||||||||||||||||||||||||||||||||||
| 33 | region | ||||||||||||||||||||||||||||||||||
| 34 | service | ||||||||||||||||||||||||||||||||||
| 35 | signature_version | ||||||||||||||||||||||||||||||||||
| 36 | queue_list | ||||||||||||||||||||||||||||||||||
| 37 | name | ||||||||||||||||||||||||||||||||||
| 38 | max_messages | ||||||||||||||||||||||||||||||||||
| 39 | url | ||||||||||||||||||||||||||||||||||
| 40 | visibility_timeout | ||||||||||||||||||||||||||||||||||
| 41 | wait_time | ||||||||||||||||||||||||||||||||||
| 42 | ) | ||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | use parent qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 2 | our @VALID_MESSAGE_TYPES = qw( | |||||||||||||||||||||||||||||||||
| 48 | text/plain | ||||||||||||||||||||||||||||||||||
| 49 | application/json | ||||||||||||||||||||||||||||||||||
| 50 | application/x-www-form-urlencoded | ||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 2 | our $DEFAULT_ENDPOINT_URL = 'https://queue.amazonaws.com'; | |||||||||||||||||||||||||||||||||
| 54 | 2 | our $MAX_MESSAGES = 1; | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 2 | our $TRUE = 1; | |||||||||||||||||||||||||||||||||
| 57 | 2 | our $FALSE = 0; | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 61 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 62 | 1 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | my $options = ref $args[0] ? $args[0] : {@args}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | $options->{credentials} //= Amazon::Credentials->new; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options->{"credentials"} //= "Amazon::Credentials"->new
MC/DC0%0/2
$options->{"credentials"} //= "Amazon::Credentials"->new
$options->{"credentials"}
"Amazon::Credentials"->new
Truth table33%1/3
A //= B
A= $options->{"credentials"}B= "Amazon::Credentials"->new
| |||||||||||||||||||||||||||||||||||
| 67 | 1 | my $self = $class->SUPER::new($options); | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 1 | $self->init_defaults(); | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 1 | $self->create_service(); | |||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if ( $self->get_name && !$self->get_url ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->get_name and not $self->get_url
MC/DC0%0/2
$self->get_name and not $self->get_url
$self->get_name
not $self->get_url
Truth table33%1/3
A and not(B)
A= $self->get_nameB= not $self->get_url
| |||||||||||||||||||||||||||||||||||
| 74 | 0 | my %queue_list = reverse $self->list_queues(); | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( $self->get_create_queue ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->create_queue( $self->get_name ); | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||
| 80 | 0 | my $queue_url = $queue_list{ $self->get_name }; | |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | die sprintf "no such queue [%s]\n", $self->get_name | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | if !$queue_url; | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->set_url($queue_url); | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | die "no queue url set\n" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | if !$self->get_url; | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 1 | $self->create_request; | |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 1 | return $self; | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | sub init_defaults { | ||||||||||||||||||||||||||||||||
|
Subroutine
init_defaults: called CC=11 SCAR=33.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 99 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 100 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 1 | my $config = $self->get_config; | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | # init options from config... | ||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | if ($config) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 106 | 0 | foreach ( | |||||||||||||||||||||||||||||||||
| 107 | qw( | ||||||||||||||||||||||||||||||||||
| 108 | handler_message_type | ||||||||||||||||||||||||||||||||||
| 109 | aws_endpoint_url | ||||||||||||||||||||||||||||||||||
| 110 | queue_max_error_retry | ||||||||||||||||||||||||||||||||||
| 111 | queue_max_messages | ||||||||||||||||||||||||||||||||||
| 112 | queue_url | ||||||||||||||||||||||||||||||||||
| 113 | queue_name | ||||||||||||||||||||||||||||||||||
| 114 | queue_create_queue | ||||||||||||||||||||||||||||||||||
| 115 | queue_visibility_timeout | ||||||||||||||||||||||||||||||||||
| 116 | queue_wait_time | ||||||||||||||||||||||||||||||||||
| 117 | ) | ||||||||||||||||||||||||||||||||||
| 118 | ) { | ||||||||||||||||||||||||||||||||||
| 119 | 0 | my $getter = "get_$_"; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( $config->can($getter) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | 0 | my @local_name = split /_/xsm, $_; | |||||||||||||||||||||||||||||||||
| 124 | 0 | shift @local_name; | |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 0 | my $var = join q{_}, @local_name; | |||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | next | ||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if defined $self->get($var); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->set( $var, $config->$getter() ); | |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | my $message_type = $self->get_message_type // 'text/plain'; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_message_type // "text/plain"
MC/DC0%0/1
$self->get_message_type // "text/plain"
$self->get_message_type
Truth table50%1/2
A
A= $self->get_message_type
| |||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | die "invalid message type\n" | ||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | if none { $message_type eq $_ } @VALID_MESSAGE_TYPES; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 1 | $self->set_message_type($message_type); | |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | my $endpoint_url //= $self->get_endpoint_url; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
my $endpoint_url //= $self->get_endpoint_url
MC/DC0%0/2
my $endpoint_url //= $self->get_endpoint_url
my $endpoint_url
$self->get_endpoint_url
Truth table33%1/3
A //= B
A= my $endpoint_urlB= $self->get_endpoint_url
| |||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | $endpoint_url //= $ENV{AWS_ENDPOINT_URL} // $DEFAULT_ENDPOINT_URL; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$endpoint_url //= $ENV{"AWS_ENDPOINT_URL"} // $Amazon::SQS::QueueHandler::DEFAULT_ENDPOINT_URL
$ENV{"AWS_ENDPOINT_URL"} // $Amazon::SQS::QueueHandler::DEFAULT_ENDPOINT_URL
MC/DC0%0/3
$endpoint_url //= $ENV{"AWS_ENDPOINT_URL"} // $Amazon::SQS::QueueHandler::DEFAULT_ENDPOINT_URL
$endpoint_url
$ENV{"AWS_ENDPOINT_URL"}
$Amazon::SQS::QueueHandler::DEFAULT_ENDPOINT_URL
Truth table0%0/4
A //= B // C
A= $endpoint_urlB= $ENV{"AWS_ENDPOINT_URL"}C= $Amazon::SQS::QueueHandler::DEFAULT_ENDPOINT_URL
| |||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 1 | $self->set_endpoint_url($endpoint_url); | |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | my $max_messages = $self->get_max_messages() || 1; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_max_messages || 1
MC/DC0%0/1
$self->get_max_messages || 1
$self->get_max_messages
Truth table50%1/2
A
A= $self->get_max_messages
| |||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 1 | $self->set_max_messages( max( $MAX_MESSAGES, $max_messages ) ); | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 1 | return; | |||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub create_queue { | ||||||||||||||||||||||||||||||||
|
Subroutine
create_queue: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 157 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 158 | 0 | my ( $self, $queue_name ) = @_; | |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $queue_list = $self->get_queue_list // {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_queue_list // {}
MC/DC0%0/1
$self->get_queue_list // {}
$self->get_queue_list
Truth table0%0/2
A
A= $self->get_queue_list
| |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 0 | my $queue_url = eval { | |||||||||||||||||||||||||||||||||
| 163 | return $queue_list->{$queue_name} | ||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if $queue_list->{$queue_name}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 0 | my $service = $self->get_service; | |||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | 0 | my $rsp = $service->createQueue( { QueueName => $queue_name } ); | |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | 0 | my $result = $rsp->getCreateQueueResult(); | |||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 0 | return $result->getQueueUrl; | |||||||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | die "could not create queue $queue_name\n$EVAL_ERROR" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $queue_url or $Amazon::SQS::QueueHandler::EVAL_ERROR
MC/DC0%0/2
not $queue_url or $Amazon::SQS::QueueHandler::EVAL_ERROR
not $queue_url
$Amazon::SQS::QueueHandler::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not $queue_urlB= $Amazon::SQS::QueueHandler::EVAL_ERROR
| |||||||||||||||||||||||||||||||||||
| 176 | if !$queue_url || $EVAL_ERROR; | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->set_url($queue_url); | |||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | 0 | return $queue_url; | |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub list_queues { | ||||||||||||||||||||||||||||||||
|
Subroutine
list_queues: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 185 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 186 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 0 | my $service = $self->get_service(); | |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 0 | my $rsp = $service->listQueues(); | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | 0 | my $result = $rsp->getListQueuesResult(); | |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | 0 | my $queueUrls = $result->getQueueUrl(); | |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | 0 | my %queue_list; | |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 0 | foreach ( @{$queueUrls} ) { | |||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if (/\/([^\/]+)$/xsm) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 200 | 0 | $queue_list{$_} = $1; | |||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->set_queue_list( \%queue_list ); | |||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | 0 | return %queue_list; | |||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | sub create_service { | ||||||||||||||||||||||||||||||||
|
Subroutine
create_service: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 211 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 212 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | 1 | my %options = ( | |||||||||||||||||||||||||||||||||
| 215 | ServiceURL => $self->get_endpoint_url, | ||||||||||||||||||||||||||||||||||
| 216 | MaxErrorRetry => $self->get_max_error_retry, | ||||||||||||||||||||||||||||||||||
| 217 | credentials => $self->get_credentials, | ||||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 1 | my $service = eval { return Amazon::SQS::Client->new( undef, undef, \%options ); }; | |||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | die "could not create service\n$EVAL_ERROR" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $service or $Amazon::SQS::QueueHandler::EVAL_ERROR
MC/DC0%0/2
not $service or $Amazon::SQS::QueueHandler::EVAL_ERROR
not $service
$Amazon::SQS::QueueHandler::EVAL_ERROR
Truth table33%1/3
not(A) or B
A= not $serviceB= $Amazon::SQS::QueueHandler::EVAL_ERROR
| |||||||||||||||||||||||||||||||||||
| 223 | if !$service || $EVAL_ERROR; | ||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 1 | $self->set_service($service); | |||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||
| 227 | 1 | return $service; | |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | sub decode_message { | ||||||||||||||||||||||||||||||||
|
Subroutine
decode_message: called CC=10 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 232 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 233 | 4 | my ( $self, $message_type, $message_body ) = @_; | |||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||
| 235 | 4 | ▶ | $message_type //= $self->get_message_type; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$message_type //= $self->get_message_type
MC/DC0%0/2
$message_type //= $self->get_message_type
$message_type
$self->get_message_type
Truth table33%1/3
A //= B
A= $message_typeB= $self->get_message_type
| |||||||||||||||||||||||||||||||||||
| 236 | 4 | ▶ | $message_body //= $self->get_message_body; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$message_body //= $self->get_message_body
MC/DC0%0/2
$message_body //= $self->get_message_body
$message_body
$self->get_message_body
Truth table33%1/3
A //= B
A= $message_bodyB= $self->get_message_body
| |||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 4 | $self->get_logger->trace( | |||||||||||||||||||||||||||||||||
| 239 | Dumper( | ||||||||||||||||||||||||||||||||||
| 240 | [ type => $message_type, | ||||||||||||||||||||||||||||||||||
| 241 | body => $message_body, | ||||||||||||||||||||||||||||||||||
| 242 | ] | ||||||||||||||||||||||||||||||||||
| 243 | ) | ||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | 4 | my $decoded_message = eval { | |||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | return $message_body | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 248 | if $message_type eq 'text/plain'; | ||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | return JSON->new->decode($message_body) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 251 | if $message_type eq 'application/json'; | ||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | 1 | ▶ | if ( $message_type eq 'application/x-www-form-encoded' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 254 | 1 | my %vars = CGI::Simple->new($message_body)->Vars(); | |||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | # create array refs from multi-value params | ||||||||||||||||||||||||||||||||||
| 257 | 1 | foreach ( keys %vars ) { | |||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | next if $vars{$_} !~ /\0/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 259 | 1 | $vars{$_} = [ split /\0/xsm, $vars{$_} ]; | |||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 1 | return \%vars; | |||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||
| 264 | }; | ||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | 4 | ▶ | die "unable to decode message\n$EVAL_ERROR" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $decoded_message or $Amazon::SQS::QueueHandler::EVAL_ERROR
MC/DC0%0/2
not defined $decoded_message or $Amazon::SQS::QueueHandler::EVAL_ERROR
not defined $decoded_message
$Amazon::SQS::QueueHandler::EVAL_ERROR
Truth table33%1/3
not(A) or B
A= not defined $decoded_messageB= $Amazon::SQS::QueueHandler::EVAL_ERROR
| |||||||||||||||||||||||||||||||||||
| 267 | if !defined $decoded_message || $EVAL_ERROR; | ||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 4 | $self->set_message($decoded_message); | |||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||
| 271 | 4 | return $decoded_message; | |||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | sub handler { | ||||||||||||||||||||||||||||||||
|
Subroutine
handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 276 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 277 | 0 | my ( $self, $message ) = @_; | |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | 0 | $self->get_logger->info( Dumper( [ message => $message ] ) ); | |||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||
| 281 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||
| 284 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub get_next_message { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_next_message: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 286 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 287 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | 0 | $self->set_message(undef); | |||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 0 | my $service = $self->get_service; | |||||||||||||||||||||||||||||||||
| 292 | 0 | my $request = $self->get_request; | |||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | 0 | my $response = $service->receiveMessage($request); | |||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | return | ||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if !$response || !$response->isSetReceiveMessageResult(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response and $response->isSetReceiveMessageResult
MC/DC0%0/2
$response and $response->isSetReceiveMessageResult
$response
$response->isSetReceiveMessageResult
Truth table0%0/3
A and B
A= $responseB= $response->isSetReceiveMessageResult
| |||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | 0 | my $receiveMessageResult = $response->getReceiveMessageResult(); | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | 0 | my $messageList = $receiveMessageResult->getMessage(); | |||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | my ($message) = @{ $messageList // [] }; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$messageList // []
MC/DC0%0/1
$messageList // []
$messageList
Truth table0%0/2
A
A= $messageList
| |||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | return | ||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if !ref $message || !$message->isSetMessageId(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $message and $message->isSetMessageId
MC/DC0%0/2
ref $message and $message->isSetMessageId
ref $message
$message->isSetMessageId
Truth table0%0/3
A and B
A= ref $messageB= $message->isSetMessageId
| |||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->set_raw_message($message); | |||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||
| 310 | 0 | $self->set_receipt_handle( $message->getReceiptHandle ); | |||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->set_message_body( $message->getBody() ); | |||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | 0 | $self->set_message_id( $message->getMessageId() ); | |||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||
| 316 | 0 | my $decoded_message = $self->decode_message(); | |||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | 0 | $self->set_message($decoded_message); | |||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||
| 320 | 0 | return $decoded_message; | |||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | sub create_request { | ||||||||||||||||||||||||||||||||
|
Subroutine
create_request: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 325 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 326 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | return $self->get_request | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 329 | if $self->get_request; | ||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | 1 | my $max_messages = max( 1, $self->get_max_messages ); # max of 1 currently | |||||||||||||||||||||||||||||||||
| 332 | 1 | ▶ | my $wait_time = $self->get_wait_time // 0; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_wait_time // 0
MC/DC0%0/1
$self->get_wait_time // 0
$self->get_wait_time
Truth table50%1/2
A
A= $self->get_wait_time
| |||||||||||||||||||||||||||||||||||
| 333 | 1 | my $visibility_timeout = $self->get_visibility_timeout; | |||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||
| 335 | 1 | my $request = Amazon::SQS::Model::ReceiveMessageRequest->new( | |||||||||||||||||||||||||||||||||
| 336 | { QueueUrl => $self->get_url, | ||||||||||||||||||||||||||||||||||
| 337 | MaxNumberOfMessages => $max_messages, | ||||||||||||||||||||||||||||||||||
| 338 | VisibilityTimeout => $visibility_timeout, | ||||||||||||||||||||||||||||||||||
| 339 | WaitTimeSeconds => $wait_time, | ||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||
| 341 | ); | ||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | 1 | $self->set_request($request); | |||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||
| 345 | 1 | return; | |||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||
| 348 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub change_message_visibility { | ||||||||||||||||||||||||||||||||
|
Subroutine
change_message_visibility: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 350 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 351 | 0 | my ( $self, $timeout ) = @_; | |||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||
| 353 | 0 | my $service = $self->get_service; | |||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | 0 | $service->changeMessageVisibility( | |||||||||||||||||||||||||||||||||
| 356 | QueueUrl => $self->get_url, | ||||||||||||||||||||||||||||||||||
| 357 | ReceiptHandle => $self->get_receipt_handle, | ||||||||||||||||||||||||||||||||||
| 358 | VisibilityTimeout => $timeout, | ||||||||||||||||||||||||||||||||||
| 359 | ); | ||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | 0 | return; | |||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | sub delete_message { | ||||||||||||||||||||||||||||||||
|
Subroutine
delete_message: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 366 | ######################################################################## | ||||||||||||||||||||||||||||||||||
| 367 | 0 | my ( $self, $handle ) = @_; | |||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $handle //= $self->get_receipt_handle; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$handle //= $self->get_receipt_handle
MC/DC0%0/2
$handle //= $self->get_receipt_handle
$handle
$self->get_receipt_handle
Truth table0%0/3
A //= B
A= $handleB= $self->get_receipt_handle
| |||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||
| 371 | 0 | my $logger = $self->get_logger; | |||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | 0 | my $rsp = eval { | |||||||||||||||||||||||||||||||||
| 374 | 0 | $self->get_service->deleteMessage( | |||||||||||||||||||||||||||||||||
| 375 | Amazon::SQS::Model::DeleteMessageRequest->new( | ||||||||||||||||||||||||||||||||||
| 376 | { QueueUrl => $self->get_url, | ||||||||||||||||||||||||||||||||||
| 377 | ReceiptHandle => $handle | ||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||
| 379 | ) | ||||||||||||||||||||||||||||||||||
| 380 | ); | ||||||||||||||||||||||||||||||||||
| 381 | }; | ||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||
| 383 | 0 | my $err = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||
| 385 | return | ||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | if $rsp && !$EVAL_ERROR; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rsp and not $Amazon::SQS::QueueHandler::EVAL_ERROR
MC/DC0%0/2
$rsp and not $Amazon::SQS::QueueHandler::EVAL_ERROR
$rsp
not $Amazon::SQS::QueueHandler::EVAL_ERROR
Truth table0%0/3
A and not(B)
A= $rspB= not $Amazon::SQS::QueueHandler::EVAL_ERROR
| |||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | die $err | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $err or ref $err ne "Amazon::SQS::Exception"
MC/DC0%0/2
not ref $err or ref $err ne "Amazon::SQS::Exception"
not ref $err
ref $err ne "Amazon::SQS::Exception"
Truth table0%0/3
not(A) or B
A= not ref $errB= ref $err ne "Amazon::SQS::Exception"
| |||||||||||||||||||||||||||||||||||
| 389 | if !ref $err || ref $err ne 'Amazon::SQS::Exception'; | ||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||
| 391 | 0 | my $err_message = <<'END_OF_ERROR'; | |||||||||||||||||||||||||||||||||
| 392 | Exception: %s | ||||||||||||||||||||||||||||||||||
| 393 | Response Status Code: %s | ||||||||||||||||||||||||||||||||||
| 394 | Error Code: %s | ||||||||||||||||||||||||||||||||||
| 395 | Error Type: %s | ||||||||||||||||||||||||||||||||||
| 396 | Request ID: %s | ||||||||||||||||||||||||||||||||||
| 397 | END_OF_ERROR | ||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||
| 399 | 0 | die sprintf $err_message, | |||||||||||||||||||||||||||||||||
| 400 | $err->getMessage, | ||||||||||||||||||||||||||||||||||
| 401 | $err->getStatusCode, | ||||||||||||||||||||||||||||||||||
| 402 | $err->getErrorCode, | ||||||||||||||||||||||||||||||||||
| 403 | $err->getErrorType, | ||||||||||||||||||||||||||||||||||
| 404 | $err->getRequestId; | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | 0 | return; | |||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | __END__ | ||||||||||||||||||||||||||||||||||