I am planning on writing a Perl script that will be run on a variety of different platforms and Perl installations (both version numbers and module configurations). Because sometimes I can not or do not wish to control the installation and because some things work on Unix-type machines but do not on Windows, I would like to write my program so that it chooses which module or code to use for a particular task. So, I have two general questions:

How does a module such as CPAN test whether or not the user has Net::FTP or LWP, etc., installed and working? I tried looking through the code, but could not find the answer. In general, what methods should I use to determine whether or not I can use module Foo::Bar? Are there methods preferred to liberal use of eval? Also, I am considering not only checking whether or not a module is available but also running some (of my own) test cases against it. Is this a good idea and does anyone have any experience with this? (That is, running test cases and reacting to them within a single program.)

Secondly, I'd like for the program to check for module availability on its first run and then simply proceed to use what it determined was usable (as the first run may take a while). However, perhaps when a new module is installed or something, I would like to rerun the configuration procedure. Is there a configuration module that would help me here? How should I store the data of "this module works but this one doesn't" and then use it when necessary?

I tried searching Perlmonks but could not find anything. Thanks very much in advance for your assistance.


In reply to Gracefully choosing which module to use by kaif

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.