I concur with the "eval use".

I have an application which currently uses this system and it works perfectly. You may want to check $@ for problems during the execution of the eval, but otherwise all is well.

In my usage, this technique allows me to include OS-specific modules and code while leaving the main application oblivious to the OS-specific differences. I am basically using $^O ($OSNAME) to decide what modules to load with "eval use".

The application in question is a custom build system. I have a function that is called "build_installer" that is really implemented 5 different ways on different platforms, all without any sort of if blocks. I simply implemented the function 5 different times in 5 different modules and pick the right one at runtime based on the OS the user is running. This way, the Win32 version can use Win32 modules without caring about not being able to run those under Linux, etc.


In reply to Re: Re: Load all modules in directory by flyingmoose
in thread Load all modules in directory by ttcuberat

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.