Subject: | timeout_call warns on exception with string but not numeric overload |
Date: | Tue, 26 Sep 2017 17:02:18 +0100 |
To: | bug-Sys-SigAction [...] rt.cpan.org |
From: | ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker) |
Hi,
If the code run by timeout_call() throws an exception object that has
string overloading but not numeric overloading, a warning is triggered.
See the attached test for a demonstration.
One way to avoid this would be to check that the exception isn't blessed
before comparing it to TIMEDOUT.
--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of." -- Skud's Meta-Law
use strict;
use warnings;
use Test::More;
use Sys::SigAction qw(timeout_call);
{
package MyException;
use overload '""' => sub { $_[0]->{msg} },
fallback => 1;
sub throw { die bless { msg => $_[1] }, $_[0] }
}
$SIG{__WARN__} = sub { fail "no warning"; diag $_[0] };
eval {
timeout_call(0.1, sub { MyException->throw("Something went wrong"); })
};
my $err = $@;
isa_ok($@, 'MyException', 'The exception');
done_testing;