our
$VERSION
=
'1.11'
;
__PACKAGE__->mk_accessors(
qw/ sns arn /
);
sub
Publish
{
my
(
$self
,
$msg
,
$subj
,
$attr
) =
@_
;
my
$structure
=
undef
;
my
$attributes
=
undef
;
if
(
ref
(
$msg
) eq
'HASH'
) {
$structure
=
'json'
;
$msg
= encode_json(
$msg
);
}
if
(
defined
(
$attr
) and
ref
(
$attr
) eq
'HASH'
) {
my
$i
= 1;
foreach
my
$key
(
keys
%$attr
) {
$attributes
->{
"MessageAttributes.entry.$i.Name"
} =
$key
;
$attributes
->{
"MessageAttributes.entry.$i.Value.DataType"
} =
$attr
->{
$key
}->{
'Type'
};
if
(
$attr
->{
$key
}->{
'Type'
} eq
'Binary'
) {
$attributes
->{
"MessageAttributes.entry.$i.Value.BinaryValue"
} =
$attr
->{
$key
}->{
'Value'
};
}
else
{
$attributes
->{
"MessageAttributes.entry.$i.Value.StringValue"
} =
$attr
->{
$key
}->{
'Value'
};
}
$i
++;
}
}
my
$r
=
$self
->sns->dispatch({
'Action'
=>
'Publish'
,
'TargetArn'
=>
$self
->arn,
'Message'
=>
$msg
,
'MessageStructure'
=>
$structure
,
'Subject'
=>
$subj
,
'Attributes'
=>
$attributes
,
});
return
$r
?
$r
->{
'PublishResult'
}{
'MessageId'
} :
undef
;
}
1;