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

I'm working on a module that provides a simple interface to procedures that are very different in different operating systems. In one OS, I'm probably fine just using core perl and in others I might have to build C code.

To be specific, I want to make dropping root/admin privileges easier. I need to handle uid,gid,euid,egid,supplimental gids, saved uid and saved gid etc. in unix and I don't even know what I'd need to do in Windows. That's not my question though.

My question is about making a build process that produces the correct module for each supported platform. E.G. if I'm on Linux I want to handle saved uids correctly, but if I'm on some unix that only has uid & euid, I don't want my module to freak out looking for libraries to support saved uids.

What's the best way to make a module differently depending on the platform?

Thanks!
-Pileofrogs

Replies are listed 'Best First'.
Re: Portable Build
by Corion (Patriarch) on Apr 30, 2008 at 20:27 UTC

    Have one front-end module (the fancy name might be "factory") and OS specific back-end modules. Like Widget, which implements the API, and loads Widget::Win32 or Widget::Linux or Widget::Generic, depending on the OS it runs under.

    Also, on Windows, you don't have any of the setuid calls I think.

Re: Portable Build
by Herkum (Parson) on Apr 30, 2008 at 21:29 UTC

    Delve into Module::Build and understand how it is supposed to work, both as a installation program, and how it works with various systems. It contains modules that are used when it is run on different operating systems. That sounds like want you are planning on doing.