Hi,

(Sorry ... couldn't think of a decent title.)

Suppose I have a module (an extension) called G.pm. The source distro contains a very basic 'Makefile.PL', a 'G.pm' and a 'G.xs' (along with the usual supplementary files). The G.pm functions work differently, according to whether the operating system is Win32 or not - so there's a lot of checking to see whether $^O is 'MSWin32' or not. Similarly, in the XS file there's a need to #ifdef WIN32. It works fine .... but it might be cleaner if it was set up so that G.pm simply determined whether $^O was 'MSWin32', and then called either G/Win32.pm or G/Unix.pm (as appropriate).

There's an example of splitting things up along these lines in (an old version of) the File::Spec distro - but it's pure perl ... and how to incorporate the XS element into such a split has me baffled.

Questions that come to mind:
Do I split the XS file into 2 separate files (one for Win32, one for Unix) as well ?
If so, what do I call them and where do I place them ?
Is there a CPAN distro that provides a good demo of how to achieve this when XS is involved ?

The actual module in question is FileHandle::Fmode and I think it was suggested, quite some time ago, by dragonchild and/or BrowserUK that it be split along the lines that I've indicated here. (I've only just now got round to giving that serious consideration ... and sort of wish I hadn't :-)

I had a bit of a speculative play around ... to the point where it became apparent that I should stop speculating, and start asking for a pointer or two.

Cheers,
Rob

In reply to Splitting an extension based on OS by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.