Closed ppisar closed 4 years ago
It can be reduced to:
$ cat /tmp/test
if (eval 0) {
\&Time::HiRes::time;
}
require Log::Log4perl::Util;
if (Log::Log4perl::Util::module_available("Time::HiRes")) {
print "BUG\n";
}
[test@fedora-34 Log-Log4perl-1.52]$ perl -Ilib /tmp/test
BUG
It seems that \&Time::HiRes::time autovivifies %{'Time::HiRes::'} and hence Log::Log4perl::Util::module_available("Time::HiRes") thinks that Time::HiRes has already been loaded.
If I replace "eval 0" condition with "0", perl optimizes out the block with the vivification.
Benchmark.pm basically does:
if (eval 'require Time::HiRes;') {
\&Time::HiRes::time;
}
Thanks for the report. I think the module_available
change was wrong, and needs changing. Things that define a package inline will just have to set a %INC
entry so require
does the right thing.
The change in #61 has been (I believe) fixed. Could you try again with the just-released 1.53? Please reopen if it's not actually fixed!
Thank you for the quick fix. I confirm that 1.53 passes without Time::HiRes.
If Time::HiRes is not available, t/013Bench.t fails:
I can see that lib/Log/Log4perl/Util/TimeTracker.pm loads Time::HiRes only if Log::Log4perl::Util::module_available returns true. Compiling TimeTracker.pm indeed succeeds. But Benchmark in the t/013Bench.t does something strange that confuses module_available():