From 55fea7cdfa7133ed7bd545a49713b833892ab6fb Mon Sep 17 00:00:00 2001 From: Ash Berlin Date: Thu, 26 Mar 2009 10:20:46 +0000 Subject: [PATCH] Remove warning from using try at package level --- lib/TryCatch/Exception.pm | 2 +- t/simple.t | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/TryCatch/Exception.pm b/lib/TryCatch/Exception.pm index 992e94c..8fe0acd 100644 --- a/lib/TryCatch/Exception.pm +++ b/lib/TryCatch/Exception.pm @@ -47,7 +47,7 @@ sub run { local $CTX = $CTX; my ($package) = caller(1); - if ($package eq __PACKAGE__) { + if (defined $package && $package eq __PACKAGE__) { # nested: try { try {} } die "Internal Error: Nested try without CTX" unless defined $CTX; } else { diff --git a/t/simple.t b/t/simple.t index 3184ab0..89a3e2e 100644 --- a/t/simple.t +++ b/t/simple.t @@ -39,6 +39,8 @@ is(simple_no_return(), "bar", "try without explicity return"); is(use_test(), 42, "use in try block"); my $ran_catch = 0; +my $warnings = 0; +$SIG{__WARN__} = sub { $warnings++; CORE::warn(@_) }; try { foo(); @@ -47,6 +49,7 @@ catch ($e) { $ran_catch = 1; } is($ran_catch, 0, "Catch block not run"); +is($warnings, 0, "No warnings from try in not in sub"); sub foo { return 1;