I approach this a bit differently, by having n+1 modules for n platforms like this:
package My::Functions; use strict; my $OS_TYPE = $^O eq 'MSWin32' ? 'win' : ($^O eq 'nonstop_kernel' ? 'nsk' : 'unix'); if ($OS_TYPE eq 'win') { require My::Functions::Win32; } else { require My::Functions::Unix; }; 1; # ---- File My/Functions/Win32.pm: package My::Functions::Win32; package My::Functions; sub foo {}; # ---- File My/Functions/Unix.pm: package My::Functions::Unix; package My::Functions; sub foo {};
That way, I lose access to the Unix functions under Win32 and vice versa, but the functions live all in the My::Functions namespace and not below it, which I find nice and more convenient. Functions common to all platforms end up in My/Functions.pm.
In reply to Re: Seeking good ways to structure cross-platform code
by Corion
in thread Seeking good ways to structure cross-platform code
by eyepopslikeamosquito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |