It's not very elegant, but what about adding a lexical flag that gets set in your alarm handler?
{
my $timed_out = 0;
local $SIG{ ALRM } = sub { $timed_out++; die 'timeout' };
alarm( MAX_SECONDS );
eval {
molasses_in_january();
alarm( 0 );
};
if ( $@ ) {
die $@ if ! $timed_out;
handle_timeout();
}
}
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.