I love learning things, and this was no exception.

First of all, a minor clarification:

perl is smarter than me, in fact much to my consternation it's sometimes just darn clever (didn't it read Damian's book?). IAC, File::Glob does not get loaded at runtime. The compiler apparently notices you used <*> or glob() and loads File::Glob at compile time. So my solution of wrapping our glob() calls in an eval{} woulod not work.

So I had to fight clever with clever. I'm sure this can be improved, so I'd love commentary. Here's the setup:

Module A uses Module B Module B has glob() calls

So I went into Module A and removed the use Module B; and replaced it with this:

BEGIN { # Module B was failing to compile on a very random schedule. The # failure was actually on Windows only, and had to do with the # perl compiler seeing use of the glob() function, and # proceeding to load the File::Glob module, including the # File::Glob.dll. In some very rare occurrances, it # would fail, claiming the .dll was not valid. # # Since this was a compile time failure, we needed to find a # clever way to catch it unfortunately. This might just work. # # Try 5 times to load the module my $retry = 5; my $succeed = 0; while ( $retry-- > 0 ) { eval { require ModuleB; import ModuleB; }; if ( $@ ) { # Print an error it if failed print "INTERNAL ERROR: ModuleB failed to compile. Retrying\n" +; # Delete the key from the %INC hash, otherwise it # will refuse to try to reload it again delete $INC{ 'ModuleB.pm' }; # Undef the whole darn namespace, to avoid any errors # about redefining things in the namespace undef %ModuleB:: ; } else { $retry = 0; $succeed = 1; } } # If it never loaded, bail for good. if ( $succeed == 0 ) { require Carp; Carp::croak("Failed to load ModuleB: $@\n"); } }

Some limited testing done by forcing a croak() in ModuleB on the first 4 attempts shows it seems to work. We'll see in production use!


In reply to Re^4: Problems sometimes loading File::Glob by HuckinFappy
in thread Problems sometimes loading File::Glob by HuckinFappy

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.