line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AWS::SNS::Confess; |
2
|
|
|
|
|
|
|
# ABSTRACT: Publish errors to an SNS topic |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
99370
|
use base 'Exporter'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
159
|
|
5
|
2
|
|
|
2
|
|
683
|
use Amazon::SNS; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Devel::StackTrace; |
7
|
|
|
|
|
|
|
use strict; |
8
|
|
|
|
|
|
|
use warnings 'all'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw/confess/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our ($access_key_id, $secret_access_key, $topic, $sns, $sns_topic); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub setup |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
my (%args) = @_; |
17
|
|
|
|
|
|
|
$access_key_id = $args{access_key_id}; |
18
|
|
|
|
|
|
|
$secret_access_key = $args{secret_access_key}; |
19
|
|
|
|
|
|
|
$topic = $args{topic}; |
20
|
|
|
|
|
|
|
$sns = $args{sns} || Amazon::SNS->new({ |
21
|
|
|
|
|
|
|
key => $access_key_id, |
22
|
|
|
|
|
|
|
secret => $secret_access_key, |
23
|
|
|
|
|
|
|
}); |
24
|
|
|
|
|
|
|
$sns->service(_service_url()); |
25
|
|
|
|
|
|
|
$sns_topic = $sns->GetTopic($topic); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub confess |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
my ($msg) = @_; |
31
|
|
|
|
|
|
|
my $full_message = "Runtime Error: $msg\n" |
32
|
|
|
|
|
|
|
. Devel::StackTrace->new->as_string; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
_send_msg( $full_message ); |
35
|
|
|
|
|
|
|
die $msg; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _service_url |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
die "no topic specified" unless $topic; |
41
|
|
|
|
|
|
|
if ($topic =~ m/^arn:aws:sns:([^:]+):\d+:[^:]+$/) |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
return "http://sns.$1.amazonaws.com"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
return "http://sns.us-east-1.amazonaws.com"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _send_msg |
49
|
|
|
|
|
|
|
{ |
50
|
|
|
|
|
|
|
$sns_topic->Publish(shift); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |