Subject: | indirect.pm breaks %^H |
Date: | Tue, 5 Jul 2011 17:41:54 +0100 |
To: | bug-indirect [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
An interaction between indirect.pm and implicit module loading breaks %^H.
I'm seeing this on Perl 5.10.1, where some code that I'm running at
compile time happens to perform a utf8 regexp match and this overwrites
the contents of %^H, but only if indirect.pm was loaded earlier.
Here's my test case:
$ perl -le 'require indirect; %^H=(foo=>1,bar=>2); print join",",%^H; $x = "foo"; utf8::upgrade($x); $x =~ /foo/i; print join",",%^H'
bar,2,foo,1
indirect,,bar,2,foo,1
The extra entry in %^H is indirect=>undef. If I'm loading
Lexical::SealRequireHints as well, due to using one of my lexical-scoping
modules, the old %^H entries disappear:
$ perl -le 'use Lexical::SealRequireHints; require indirect; %^H=(foo=>1,bar=>2); print join",",%^H; $x = "foo"; utf8::upgrade($x); $x =~ /foo/i; print join",",%^H'
bar,2,foo,1
indirect,
It looks as though indirect is causing the %^H of some module's
compilation to be copied into the runtime %^H. L:SRH causes the old %^H
contents to disappear because it prevents the old entries leaking *into*
the module's compilation.
I have not managed to reproduce the problem by replacing the regexp
match with 'require "utf8_heavy.pl"' or any other single require.
Unsurprisingly, the problem does not occur on 5.12.
Taking into account the previous issues we've had with indirect.pm
leaking lexical state, it appears that its workaround for the core bug is
difficult to get right. You might want to consider using L:SRH instead,
which seems to be more reliable.
-zefram