From: Matt S Trout Date: Mon, 30 Jul 2012 12:33:06 +0000 (+0000) Subject: don't try and call a method on a weakened object that already disappeared X-Git-Tag: v1.000000~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cfc04a372f9abeabe532ef25c3fe0c188a0a5232;p=p5sagit%2Fcurry.git don't try and call a method on a weakened object that already disappeared --- diff --git a/lib/curry.pm b/lib/curry.pm index c98eab5..544013e 100644 --- a/lib/curry.pm +++ b/lib/curry.pm @@ -22,6 +22,7 @@ sub AUTOLOAD { my ($method) = our $AUTOLOAD =~ /^curry::(.+)$/; my @args = @_; return sub { + return unless $invocant; $invocant->$method(@args => @_); } } @@ -52,7 +53,10 @@ is equivalent to: my $code = do { Scalar::Util::weaken(my $weak_obj = $obj); - sub { $weak_obj->frobnicate(foo => @_) }; + sub { + return unless $weak_obj; # in case it already went away + $weak_obj->frobnicate(foo => @_) + }; }; =head1 RATIONALE