I need to implement less-than-a-second timeouts in the DBIx::HA package. Having the following code from that module:
my $timeout = 0;
eval {
no strict;
my $h = set_sig_handler(
'ALRM',
sub { $timeout = 1; die 'TIMEOUT'; },
{ mask=>['ALRM'], safe=>1 }
);
alarm($DATABASE::conf{_getdbname($dsn)}->{'connecttimeout'});
$dbh = DBI->connect($dsn, $username, $auth, $attrs);
alarm(0);
};
I know that there is a core Perl module Time::HiRes, but I never used it before. It also has an alarm()
sub - may I just insert use Time::HiRes qw (alarm);
before the lines above? Or maybe I should somehow adapt the lines above? I haven't found any obvious example.