On Sat Jan 21 21:58:16 2012, SPROUT wrote:
Show quoted text> On Sat Jan 21 21:32:23 2012, SPROUT wrote:
> > $ perl5.15.6 -Mblib t/hints.t
> > ok 1 - Basic non-strict eval ok
> > ok 2 - Lexical not stored
> > ok 3 - Unable to use undeclared variable
> > not ok 4 - Correct message in $@
> > # Failed test 'Correct message in $@'
> > # at t/hints.t line 28.
> > # 'Variable "$x" is not imported at (eval) line 2.
> > # '
> > # doesn't match '(?^:requires explicit package)'
> > ok 5 - Hints are set per strictures
> > ok 6 - Lexical not stored
> > ok 7 - Lexical pragma used below main scope not captured
> > ok 8 - Lexical pragma captured
> > 1..8
> > # Looks like you failed 1 test of 8.
>
> It seems that this test:
>
> is_deeply(
> [ $eval->eval('$x = 1') ],
> [ 1 ],
> 'Basic non-strict eval ok'
> );
>
> is causing the *x to exist for the next eval, which then emits a
> ‘Variable is not imported’
> warning (since the *x glob exists), which, due to fatal warnings, ends
> up in $@ instead of the
> ‘Global symbol $x require explicit package’ that usually follows.
In earlier perls, the ‘Variable is not imported’ warning is caught by the __WARN__ handler.
Then the ‘Global symbol’ error exits the eval and ends up in $@.
In bleadperl, do "string" propagates warning hints, causing fatal warnings to turn ‘Variable is
not imported’ into an error:
my $code = 'use strict; $x; 1';
my $text_ref = \$code;
local @INC = (sub {
if ($_[1] eq '/eval_do') {
open my $fh, '<', $text_ref;
$fh;
} else {
();
}
}, @INC);
*x;
use warnings FATAL => 'all';
do '/eval_do' or die "error is [$@]";
That gives:
error is [Variable "$x" is not imported at /loader/0x803a10//eval_do line 1.
] at - line 13.
Arguably, Eval::WithLexicals should be producing exactly that behaviour anyway, since it
should be capturing the fatals warnings from ‘use strictures 1’.
So, by introducing a perl bug, I’ve introduced a case where two bugs cancel each other out.
:-)
I obviously need to fix the perl bug.
But Eval::WithLexicals ought to be propagating ${^WARNING_BITS}, not just *^H.