.. demands that a library file be included if it hasn't already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of "eval"

I can't find a definition of exactly what "included" means, but you seem to be saying that if the file is found, and is readable, and an attempt to compile and load it is made, then the file is considered to have been "included," even if the compilation or loading fails. But in fact this is not the case. Here's a pair of examples that shows the inconsistency:

#foo.pl for (1..2) { eval "use bar"; print "attempt $_: ", ($@ ? 'fail' : 'succeed'), "\n"; } #bar.pm 0 #stdout attempt 1: fail attempt 2: fail # now change bar.pm to the following: die #stdout attempt 1: fail attempt 2: succeed

In the first case, perl attempts to load bar.pm twice, but in the second case it only tries once. So apparently if a module loads successfully but returns 0, it has not been "included," but if it fails to load then it has been "included?"

Incidentally, while preparing this example I discovered a falsehood in the documentation for "use." It says that use bar is exactly equivalent to BEGIN { require bar; import bar; } but if you substitute the latter for the former in the example, the results are different.

FWIW, here's my situation. My application has a large number of modules, only a few of which are used by any given user. Currently they're all require'd at startup, with the require inside an eval so that if a module fails to load, the user is notified that it is unavailable, but he can continue to use the other modules. To reduce startup time, I want to postpone loading each module until the user explicitly activates it by clicking on it in the gui. If the user clicks on a module and it fails to load, he gets an error dialog. But if he's obstinate enough to click on it a second time, currently the application acts as if the module loaded successfully, even though it really didn't. I'm going to have to keep track explicitly of which modules the application has already attempted to load, and avoid trying any module twice. First of all, this is kind of annoying because I thought this was exactly the kind of thing that "require" was supposed to take care of. Secondly, it means that if the user fixes whatever condition caused the module not to load the first time (maybe he installed a dependency, fixed a configuration file, whatever... these modules are third-party plugins, out of my application's control) he's going to have to restart the application, which ought to be unnecessary.

Thanks for your help.


In reply to Re^2: Failed require looks like it succeeded by Anonymous Monk
in thread Failed require looks like it succeeded by Anonymous Monk

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.