Skip to content

Commit

Permalink
Fix Pushover compatibility with perl 5.8.8
Browse files Browse the repository at this point in the history
Also, validate the incoming Hashref for new() and notify() so that
a malformed hash doesn't cause a crash.   if new() is malformed,
disable Pushover.    If notify() is malformed, allow the
notify to go forward but without any optional parameters.
  • Loading branch information
George Clark committed Feb 17, 2014
1 parent 3815ce5 commit 75ac9f7
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/Pushover.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ Any of these parameters may be specified in mh.private.ini by prefixing them wit

sub new {
my ( $class, $params ) = @_;

if ( defined $params && ref($params) ne 'HASH' ) {
&::print_log(
"[Pushover] ERROR! Pushover->new() invalid parameter hash - Pushover disabled"
);
$params = {};
$params->{disable} = 1;
}

$params = {} unless defined $params;

my $self = {};
Expand Down Expand Up @@ -171,13 +180,24 @@ sub notify {

# Allow notify parameter to override global disable parameter
my $disable = $self->{disable};
$disable = $params->{disable} if ( defined $params->{disable} );

if ( defined $params && ref($params) ne 'HASH' ) {
&::print_log(
"[Pushover] ERROR! notify called with invalid parameter hash - parameters ignored"
);
&::print_log(
"[Pushover] Usage: ->push(\"Message\", { priority => 1, title => \"Some title\"})"
);
}
else {
$disable = $params->{disable} if ( defined $params->{disable} );
}

my $note = ($disable) ? '- Notifications disabled' : '';

# Copy the calling hash since we need to modify it.
if ( defined $params ) {
foreach ( keys $params ) {
if ( defined $params && ref($params) eq 'HASH' ) {
foreach ( keys %{$params} ) {
next if ( $_ eq 'disable' ); # internal override, not for pushover
$callparms->{$_} = $params->{$_};
}
Expand Down

0 comments on commit 75ac9f7

Please sign in to comment.