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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |