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

I'm not happy with some of my 7+ years old CPAN modules; they were perfect in the days before x64, Vista, and x86 Macs - but in the modern-days of complication and target platforms without compilers - I'm thinking I (we?) need to come up with a definitive "Tutorial" including template on how to actually put an xs module into CPAN in a way that has a fighting chance of actually working in real life.

Help!!!

printf("Hello from XS\n");

So here is the question:

What instructions must I follow, and what templates must I start with, in order to end up with a successful CPAN module (that includes native "C" inside it's xs), which when installed and "used" on any out-of-the-box modern PC will actually:
(A) Install, and
(B) work ?

"Modern" includes at least Windows7 (x64, ActiveState latest version, no Visual-Studio installed), XP (32), Mac (old and new - do these ship with compilers installed? - if not - then without them!), and Linux (recent, with compilers of course)

Replies are listed 'Best First'.
Re: Hard: seeking CPAN template for multiplatform xs module
by Tux (Canon) on Feb 14, 2011 at 06:58 UTC

    For XS I have only one single definite guideline: use Devel::PPPort!

    For all other things regarding XS, you'll have to rely on CPANTESTERS for all architectures that you do not have access to.

    Furthermore, you should not use any C feature that falls outside of the requirements of perl itself. Perl requires C89 C standards, so if you want to use C99 standards, you're likely to fail on (older) systems that do not have C99 compilers available. C99 features also include the dreaded use of C++ style comments, so don't use them. Ever. (Yes, I know that all compilers on windows systems support this awful comment style, so it is very tempting for developers on windows to use it.)


    Enjoy, Have FUN! H.Merijn
Re: Hard: seeking CPAN template for multiplatform xs module
by broomduster (Priest) on Feb 14, 2011 at 15:24 UTC
    What instructions must I follow, and what templates must I start with ...
    Is Module::Starter something that will help? (I came across this recently, but have not used it...)
    Mac (old and new - do these ship with compilers installed? ...
    Macs do not come with compilers installed. However, recent versions (OS X 10.5.x, a.k.a. Leopard, and 10.6.x, a.k.a. Snow Leopard) have the Developer Tools available on the DVD that's in the box. Older versions required downloading from Apple. IMO, it would be safe to assume that someone who can cope with installing a module from CPAN could also cope with installing the Developer Tools. For {,Snow }Leopard, installing the tool kit is possibly easier than installing with cpan, but that's just my $0.02.
Re: Hard: seeking CPAN template for multiplatform xs module
by Anonymous Monk on Feb 14, 2011 at 06:38 UTC
    Inline::C? XS is a very thin layer around C ... I don't think such a template can exist
Re: Hard: seeking CPAN template for multiplatform xs module
by DrHyde (Prior) on Feb 14, 2011 at 13:46 UTC

    You're looking for a way to distribute XS-ish modules without relying on the user to have a compiler? While I'm sure that you could find a way of doing it, I'm not aware of any module that does this, or of any part of the toolchain designed to help you.

Re: Hard: seeking CPAN template for multiplatform xs module
by locked_user sundialsvc4 (Abbot) on Feb 15, 2011 at 15:36 UTC

    If your module includes substantial amounts of “C” code, then the task of converting and porting it might be easy, or it might be hard, or it might be next to impossible, depending entirely upon the code.   If you are simply doing “bit-twiddling, very fast,” then the code to do this might have little more to worry its little head about than, “exactly how long is an int?”   But if your code is interacting with the operating system or with some aspect of the external environment, you might be obliged to do things in several different ways, once for each type of environment you intend to support.

    I suggest that you begin by carefully defining your problem, your example or examples, and setting appropriate-to-you boundaries around it.   Then, systematically search the prior-art within CPAN (e.g. within the Sys:: modules) that are representative of what you intend to do.   This might not be a task that can be defined “categorically,” nor with too broad of a brush with respect to operating-system platforms.   But useful and recently-maintained examples of prior art do exist.