From 75ac9f72d329777a0082ae35427c35aec7a5950a Mon Sep 17 00:00:00 2001 From: George Clark Date: Sun, 16 Feb 2014 22:15:49 -0500 Subject: [PATCH] Fix Pushover compatibility with perl 5.8.8 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. --- lib/Pushover.pm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Pushover.pm b/lib/Pushover.pm index f68af8775..4e9e1b8ec 100644 --- a/lib/Pushover.pm +++ b/lib/Pushover.pm @@ -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 = {}; @@ -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->{$_}; }