I knew someone would ask that question. :-)

Sample broken module:

use strict; use warnings; $x=1;

Sample code using string eval (the above example from Anonymous dies before the print statement because it uses a constant module name within the non-string eval form and hence is fully evaluated at compile time.)

my $sFile = 'Monks/Foo/Bar.pm'; my $result = eval("require Monks::Foo::Bar"); my $error = $@; print "=== Eval results ===\n"; print "result=<". (defined($result)?$result:'undef') .">\n\$@=<". (defined($error)?$error:'undef') .">\n"; print "=== Contents of %INC ===\n"; print "\$INC{$sFile}=<" . (defined($INC{$sFile}) ? $INC{$sFile} : 'undef') . ">\n";

Which outputs

=== Eval results === result=<undef> $@=<Global symbol "$x" requires explicit package name at Monks/Foo/Bar +.pm line 3. Compilation failed in require at (eval 1) line 3. > === Contents of %INC === $INC{Monks/Foo/Bar.pm}=<Monks/Foo/Bar.pm>

Q.E.D.

Best, beth

P.S. Using eval { $result=require($sFile); } yields the same output, so its not just the string version of eval.

Update: scripts run on Perl 5.8.8


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.