module that loads either Win32::SerialPort or Device::SerialPort, although they both provide a very similar API
I've done something like that...not an "Any" module, but conditionally loading one or the other. You do need to wrap it in a BEGIN block and eval, due to the way "use" works:
#
# Use Win32::Serial port on Windows otherwise, use Device::SerialPort
#;
BEGIN
{
my $IS_WINDOWS = ($^O eq "MSWin32" or $^O eq "cygwin") ? 1 : 0;
#
if ($IS_WINDOWS) {
eval "use Win32::SerialPort";
die "$@\n" if ($@);
} else {
eval "use Device::SerialPort";
die "$@\n" if ($@);
}
}
Then something like this when using it:
my $IS_WINDOWS = ($^O eq "MSWin32" or $^O eq "cygwin") ? 1 : 0;
if ($IS_WINDOWS) {
$serial = new Win32::SerialPort ($port, 1);
} else {
$serial = new Device::SerialPort ($port, 1);
}
Somewhat ugly, but handy for anyone using my module. There's likely some more elegant way to do it.