By loader do you mean the code that called eval require ... or Perl itself? If you mean Perl I would agree though I'm not sure how it would do it. As you say, loading isn't transactional. The partially compiled code may have successful BEGIN blocks that placed symbols in any number of namespaces, GLOBAL::CORE among them.

If by "loader" you mean the code that called eval require ..., then the problems are even greater as regards clean-up. To begin with, the caller doesn't have the kind of knowledge that the compiler does about how much was actually compiled. The compiler could keep track of all symbols it has created/modified along with their pre-load values and restore them. This isn't really something the calling code could do.

As for "doesn't make sense to continue"... that depends, at least from the caller's point of view. Indeed, it does not make sense to continue to do anything that uses the module's functionality - it is broken. However, if the module is an optional plug-in, then the brokenness may simply mean that one menu item is omitted or one item in a for-loop gets skipped with next.

There is a second issue with removing the module name from %INC: as it stands now, having the module name placed in %INC has one valuable side effect. It makes it possible to tell the difference between a call to require that fails because the module doesn't exist at all and a require that fails because the module is broken. The missing module doesn't add anything to %INC and the failed one does. That can be useful when testing - we probably don't care if a require fails because an optional module is missing. In that case we want to skip any related tests. We probably do care if a require fails because an optional module is broken. In that case we want at least one failed test for the broken compilation plus several others marked as either fail or TODO.

Without that distinction one would need to parse the exception itself - not terribly reliable when locales are taken into account. However, as discussed in the original post, that only happens on the first call to require. There after the broken and successful module both look like they succeeded.

Best, beth


In reply to Re^2: Detecting broken modules by ELISHEVA
in thread Detecting broken modules by ELISHEVA

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.