Subject: | Methods should not croak by default |
If you call
$kqueue->EV_SET( $fd, EVFILT_READ, EV_DELETE )
on a file descriptor that isn't actually being watched on anyway, it
will throw an exception by croak. It's common in fact, that this happens
because kqueue will in fact stop watching a file descriptor you
close()d, so this ends up throwing an exception.
Instead, if it simply returned true or undef on failure, the way most
system call wrappers do, we could just rely on $! to ignore these
nonfatal errors:
$kqueue->EV_SET(..) or $! == ENOENT or croak "EV_SET failed - $!";
It's not especially nice to just eval{}-wrap it, because then you catch
all failures. Since after the eval{} returns you can't really rely on
the value of $!, you'd have to test the string exception name, which now
depends on the locale's idea of what ENOENT stringifies as.
Ideally I'd request that EV_SET does not throw exceptions; instead
allowing the caller to simply "... or die" as is the usual Perl idiom.
However, there may be some API compatibility issues preventing this,
because of existing code. In that case perhaps, could there be a method
EV_SET_nothrow that simply returns undef, in the usual Perl way. You can
then trivially wrap this in
sub EV_SET { shift->EV_SET_nothrow( @_ ) or croak "EV_SET failed - $!"; }
for compatibility.
I'd be happy to supply a patch to do this if required.
--
Paul Evans