in reply to Detecting broken modules
Prove it
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Detecting broken modules
by ELISHEVA (Prior) on Jun 29, 2009 at 22:30 UTC | |
Sample broken module:
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.)
Which outputs
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 | [reply] [d/l] [select] |
by Porculus (Hermit) on Jun 30, 2009 at 22:32 UTC | |
What version of Perl are you using? I get the same results as you on an old box with 5.8.4 installed, but on my main box with 5.10.0, I get different results: $INC{module.pm} is undef if require module dies, and calling require module a second time fails. In both versions, I can trick the require into trying again, and producing the original error message for me, simply by wrapping my own call in a little localisation:
Though, on reflection, that has obvious issues for modules that really don't want to be loaded more than once, so maybe it's not a good idea. | [reply] [d/l] [select] |
by Anonymous Monk on Jun 30, 2009 at 12:44 UTC | |
| [reply] |
by ELISHEVA (Prior) on Jun 30, 2009 at 13:15 UTC | |
This isn't strictly a warnings issue but it may be exception related. Pure compilation errors also will leave %INC populated with the module. If Foo::Bar loads without compilation errors but its final statement evaluates to 0 in its last line, then $INC{$file} is undefined:
Outputs
But if it contains a reason for a compilation error (i.e. no warnings) then $INC{$file} is defined, even if the final line is 0. If, the whole file were in fact being processed and an exception thrown after the fact, I would expect undef as above. If, for example, Foo::Bar contains merely:
the output is
I don't know where to look for the source code for "require" without having to download a tarball and grepping my way through it (my google efforts found only the tarballs), but my best guess looking at the pseudocode in require is that some internal implementation of do? is dying when it finds a compilation error. I'm assuming there is some internal implementation because even though do returns undef, a compilation error causes do to set $@ to the compilation error message. Require maybe is calling this internal method but isn't trapping that properly. As a result the code that clears %INC is not being processed. But this is just a guess. Someone with internals knowledge would be better equipped to answer it. Best, beth Update: scripts run on Perl 5.8.8 | [reply] [d/l] [select] |
|
Re^2: Detecting broken modules
by Anonymous Monk on Jun 29, 2009 at 22:22 UTC | |
test.pl
| [reply] [d/l] [select] |