| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Amazon::SQS::Simple; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
113607
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
51
|
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
53
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
6
|
use Carp qw( croak ); |
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
87
|
|
|
7
|
2
|
|
|
2
|
|
699
|
use Amazon::SQS::Simple::Base; # for constants |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
111
|
|
|
8
|
2
|
|
|
2
|
|
991
|
use Amazon::SQS::Simple::Queue; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
89
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use base qw(Exporter Amazon::SQS::Simple::Base); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
864
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '2.06'; |
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( timestamp ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub GetQueue { |
|
15
|
0
|
|
|
0
|
1
|
|
my ($self, $queue_endpoint) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
if ($queue_endpoint =~ /^arn:aws:sqs/) { |
|
18
|
0
|
|
|
|
|
|
my ($host, $user, $queue); |
|
19
|
0
|
|
|
|
|
|
(undef, undef, undef, $host, $user, $queue) = split(/:/, $queue_endpoint); |
|
20
|
0
|
|
|
|
|
|
$queue_endpoint = "https://sqs.$host.amazonaws.com/$user/$queue"; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return Amazon::SQS::Simple::Queue->new( |
|
24
|
|
|
|
|
|
|
$self->{AWSAccessKeyId}, #AWSAccessKeyId and SecretKey are the first two arguments to Amazon::SQS::Simple::Base->new |
|
25
|
|
|
|
|
|
|
$self->{SecretKey}, |
|
26
|
0
|
|
|
|
|
|
%$self, |
|
27
|
|
|
|
|
|
|
Endpoint => $queue_endpoint, |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub CreateQueue { |
|
32
|
0
|
|
|
0
|
1
|
|
my ($self, $queue_name, %params) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$params{Action} = 'CreateQueue'; |
|
35
|
0
|
|
|
|
|
|
$params{QueueName} = $queue_name; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $href = $self->_dispatch(\%params); |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ($href->{CreateQueueResult}{QueueUrl}) { |
|
40
|
|
|
|
|
|
|
return Amazon::SQS::Simple::Queue->new( |
|
41
|
|
|
|
|
|
|
$self->{AWSAccessKeyId}, #AWSAccessKeyId and SecretKey are the first two arguments to Amazon::SQS::Simple::Base->new |
|
42
|
|
|
|
|
|
|
$self->{SecretKey}, |
|
43
|
|
|
|
|
|
|
%$self, |
|
44
|
|
|
|
|
|
|
Endpoint => $href->{CreateQueueResult}{QueueUrl}, |
|
45
|
0
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub ListQueues { |
|
50
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$params{Action} = 'ListQueues'; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $href = $self->_dispatch(\%params, ['QueueUrl']); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# default to the current version |
|
57
|
0
|
0
|
|
|
|
|
if ($href->{ListQueuesResult}{QueueUrl}) { |
|
58
|
|
|
|
|
|
|
my @result = map { |
|
59
|
|
|
|
|
|
|
Amazon::SQS::Simple::Queue->new( |
|
60
|
|
|
|
|
|
|
$self->{AWSAccessKeyId}, #AWSAccessKeyId and SecretKey are the first two arguments to Amazon::SQS::Simple::Base->new |
|
61
|
|
|
|
|
|
|
$self->{SecretKey}, |
|
62
|
0
|
|
|
|
|
|
%$self, |
|
63
|
|
|
|
|
|
|
Endpoint => $_, |
|
64
|
|
|
|
|
|
|
) |
|
65
|
0
|
|
|
|
|
|
} @{$href->{ListQueuesResult}{QueueUrl}}; |
|
|
0
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return \@result; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
else { |
|
70
|
0
|
|
|
|
|
|
return undef; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub timestamp { |
|
75
|
0
|
|
|
0
|
1
|
|
return Amazon::SQS::Simple::Base::_timestamp(@_); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Amazon::SQS::Simple - OO API for accessing the Amazon Simple Queue |
|
85
|
|
|
|
|
|
|
Service |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use Amazon::SQS::Simple; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $access_key = 'foo'; # Your AWS Access Key ID |
|
92
|
|
|
|
|
|
|
my $secret_key = 'bar'; # Your AWS Secret Key |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Create an SQS object |
|
95
|
|
|
|
|
|
|
my $sqs = new Amazon::SQS::Simple(AWSAccessKeyId => $access_key, SecretKey => $secret_key); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Create a new queue |
|
98
|
|
|
|
|
|
|
my $q = $sqs->CreateQueue('queue_name'); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Send a message |
|
101
|
|
|
|
|
|
|
my $response = $q->SendMessage('Hello world!'); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Send multiple messages |
|
104
|
|
|
|
|
|
|
my @responses = $q->SendMessageBatch(['Hello world', 'Farewell cruel world']); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Retrieve a message |
|
107
|
|
|
|
|
|
|
my $msg = $q->ReceiveMessage(); |
|
108
|
|
|
|
|
|
|
print $msg->MessageBody() # Hello world! |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Delete the message |
|
111
|
|
|
|
|
|
|
$q->DeleteMessage($msg->ReceiptHandle()); |
|
112
|
|
|
|
|
|
|
# or |
|
113
|
|
|
|
|
|
|
$q->DeleteMessage($msg); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Delete the queue |
|
116
|
|
|
|
|
|
|
$q->Delete(); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Purge the queue |
|
119
|
|
|
|
|
|
|
$q->Purge(); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 INTRODUCTION |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Amazon::SQS::Simple is an OO API for the Amazon Simple Queue Service. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 IMPORTANT |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This version of Amazon::SQS::Simple defaults to work against version |
|
128
|
|
|
|
|
|
|
2009-02-01 of the SQS API. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Earlier API versions may or may not work. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over 2 |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item new($access_key, $secret_key, [%opts]) |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Constructs a new Amazon::SQS::Simple object |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
C<$access_key> is your Amazon Web Services access key. C<$secret_key> is your Amazon Web |
|
141
|
|
|
|
|
|
|
Services secret key. If you don't have either of these credentials, visit |
|
142
|
|
|
|
|
|
|
L<http://aws.amazon.com/>. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Options for new: |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item Timeout => SECONDS |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Set the HTTP user agent's timeout (default is 180 seconds) |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item Version => VERSION_STRING |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Specifies the SQS API version you wish to use. E.g.: |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $sqs = new Amazon::SQS::Simple($access_key, $secret_key, Version => '2008-01-01'); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 METHODS |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 2 |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item GetQueue($queue_endpoint) |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Gets the queue with the given endpoint. Returns a |
|
169
|
|
|
|
|
|
|
C<Amazon::SQS::Simple::Queue> object. (See L<Amazon::SQS::Simple::Queue> for details.) |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item CreateQueue($queue_name, [%opts]) |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Creates a new queue with the given name. Returns a |
|
174
|
|
|
|
|
|
|
C<Amazon::SQS::Simple::Queue> object. (See L<Amazon::SQS::Simple::Queue> for details.) |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Options for CreateQueue: |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item DefaultVisibilityTimeout => SECONDS |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Set the default visibility timeout for this queue |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item ListQueues([%opts]) |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Gets a list of all your current queues. Returns an array of |
|
189
|
|
|
|
|
|
|
C<Amazon::SQS::Simple::Queue> objects. (See L<Amazon::SQS::Simple::Queue> for details.) |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Options for ListQueues: |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=over 4 |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item QueueNamePrefix => STRING |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Only those queues whose name begins with the specified string are returned. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=back |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
No functions are exported by default; if you want to use them, export them in your use |
|
206
|
|
|
|
|
|
|
line: |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
use Amazon::SQS::Simple qw( timestamp ); |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=over 2 |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item timestamp($seconds) |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Takes a time in seconds since the epoch and returns a formatted timestamp suitable for |
|
215
|
|
|
|
|
|
|
using in a Timestamp or Expires optional method parameter. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 STANDARD OPTIONS |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
The following options can be supplied with any of the listed methods. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over 2 |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item AWSAccessKeyId => STRING |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
The AWS Access Key Id to use with the method call. If not provided, Amazon::SQS::Simple uses |
|
228
|
|
|
|
|
|
|
the value passed to the constructor. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item SecretKey => STRING |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
The Secret Key to use with the method call. If not provided, Amazon::SQS::Simple uses |
|
233
|
|
|
|
|
|
|
the value passed to the constructor. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item Timestamp => TIMESTAMP |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
All methods are automatically given a timestamp of the time at which they are called, |
|
238
|
|
|
|
|
|
|
but you can override this value if you need to. The value for this key should be a |
|
239
|
|
|
|
|
|
|
timestamp as returned by the Amazon::SQS::Simple::timestamp() function. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
You generally do not need to supply this option. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item Expires => TIMESTAMP |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
All methods are automatically given a timestamp of the time at which they are called. |
|
246
|
|
|
|
|
|
|
You can alternatively set an expiry time by providing an Expires option. The value |
|
247
|
|
|
|
|
|
|
for this key should be a timestamp as returned by the C<Amazon::SQS::Simple::timestamp()> |
|
248
|
|
|
|
|
|
|
function. |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
You generally do not need to supply this option. |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=back |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Bill Alford wrote the code to support basic functionality of older API versions |
|
257
|
|
|
|
|
|
|
in release 0.9. |
|
258
|
|
|
|
|
|
|
James Neal provided the proxy support code in release 2.0 |
|
259
|
|
|
|
|
|
|
Roland Walker provided support for the newer signature version in release 2.0 |
|
260
|
|
|
|
|
|
|
Chris Jones provied the batch message code in release 2.0 |
|
261
|
|
|
|
|
|
|
Rusty Conover provided the V4 signature support in release 2.05 |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 AUTHOR |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Copyright 2007-2008 Simon Whitaker E<lt>swhitaker@cpan.orgE<gt> |
|
266
|
|
|
|
|
|
|
Copyright 2013-2017 Mike (no relation) Whitaker E<lt>penfold@cpan.orgE<gt> |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
269
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
|
272
|
|
|
|
|
|
|
|