From: Vincent Pit Date: Sat, 21 Nov 2015 14:20:47 +0000 (-0200) Subject: Make sure local_context() runs the code only when the context was found X-Git-Url: http://git.vpit.fr/?p=perl%2Fscripts%2Fxchat.git;a=commitdiff_plain;h=HEAD Make sure local_context() runs the code only when the context was found --- diff --git a/Xchat/XPI/Utils.pm b/Xchat/XPI/Utils.pm index 0b4bff9..c8994ab 100644 --- a/Xchat/XPI/Utils.pm +++ b/Xchat/XPI/Utils.pm @@ -51,9 +51,10 @@ sub local_context { return unless @_ >= 2; my $code = pop; my $new_cxt = (@_ == 1) ? $_[0] : find_context(@_); + return undef unless defined $new_cxt; my $cur_cxt = get_context; + my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard'; if (set_context $new_cxt) { - my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard'; return $code->(); } else { return undef;