I wouldn't mingle architecture dependent stuff in one module. That's a formula for hard-to-read, harder-to-maintain C-style #ifdef code.

That said, the Perl compiler will optimize away code paths that it can't possibly reach, like the following:

while (0) { for (1 .. 1000000000) {} }

Provided you have some sort of flag to mark sections of code as irrelevant to the current architecture, I think you'll be okay. (The disclaimer is that I haven't tried this in a while.)

If I were doing this, I would write wrapper classes, as you suggest. This'll provide one consistent interface for your main module to use. Your wrappers can take care of massaging the divergencies.

I'd write a tiny setup script that has the arch-dependent code in it, to check $^O and initialize the appropriate wrapper (which initializes the arch-dependent module). Then pass that wrapper instance into the constructor of the main module.

That leaves your main module relatively clean, and puts the nasty stuff away elsewhere where you don't have to work around it when you're more concerned about the business rules in your main module.


In reply to Re: Managing Architecture-Dependant Perl Modules in an Object-Oriented Hierarchy by chromatic
in thread Managing Architecture-Dependant Perl Modules in an Object-Oriented Hierarchy by princepawn

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.