module that loads either Win32::SerialPort or Device::SerialPort, although they both provide a very similar APII'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:
Then something like this when using it:# # 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 ($@); } }
Somewhat ugly, but handy for anyone using my module. There's likely some more elegant way to do 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); }
In reply to Re^2: Easing cross-platform scripting
by kschwab
in thread Easing cross-platform scripting
by White Raven
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |