dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

At F_GETFL and Win32, I was asking the question about an OS-specific issue (in this case, Win32). BrowserUk was kind enough to put a module on CPAN for me that solves my problem on Win32.

However, I'm at a loss as to how to handle this. I know how to do handle things within the code, but the packaging of the dependency tree leaves me at a loss. I currently use Module::Build with a traditional Makefile.PL generated. I have no knowledge of how anything other than CPAN.pm installs stuff or how to package something for anyone other than CPAN.pm.

Would someone please explain how to support different dependencies for different OSes in a sane fashion?


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re: OS-dependent dependencies
by syphilis (Archbishop) on Mar 09, 2006 at 04:49 UTC
    Firstly, you would want PREREQ_PM in the WriteMakefile() section of the Makefile.PL to include Win32::Fmode if and only if $^O =~ /mswin32/i. Then near the beginning of the module (.pm file) you can have something like:
    if($^O =~ /mswin32/i) {require Win32::Fmode}
    You can then access the Win32::Fmode functions by their fully qualified names. Whenever you wish to determine the read/write status of a filehandle you can do something like:
    if($^O =~ /mswin32/i) { # employ the Win32::Fmode functions } else { # employ the Fcntl flags/macro }
    Cheers,
    Rob
Re: OS-dependent dependencies
by xdg (Monsignor) on Mar 09, 2006 at 04:57 UTC
    I currently use Module::Build with a traditional Makefile.PL generated

    I don't think you're going to be able to get this to work while automatically generating a traditional Makefile.PL with Module::Build. You'll need both your Build.PL and Makefile.PL to have the OS-specific dependencies.

    Another possibility is try Module::Install and you put the OS-specific dependency logic there and let it generate your Build.PL and/or Makefile.PL... but that is just another wrapper around the problem. For example, from the Pod, an example from File::HomeDir:

    use inc::Module::Install; name 'File-HomeDir'; all_from 'lib/File/HomeDir.pm'; requires 'File::Spec' => '0.80'; build_requires 'Test::More' => '0.47'; if ( $MacPerl::Version ) { # Needed on legacy Mac OS 9 requires 'Mac::Files' => 0; } if ( $^O eq 'MXWin32' ) { # Needed on Windows platforms requires 'Win32::TieRegistry' => 0; } auto_install; WriteAll;

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: OS-dependent dependencies
by rinceWind (Monsignor) on Mar 09, 2006 at 08:51 UTC

    An alternative might be to use Module::Optional and provide dummying code for the platforms where the module is not relevant or not installed.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)