[ This post gives some of the technical details in case someone is interested. ]
Not only does it work, a fair amount of effort went into making it work.
use strict; and no strict; are executed at compile-time, yet the "refs" check is a run-time check. This is done by attaching hints to some opcodes (the same opcodes that provides line numbers for warnings and such, I think). Telling the parser which hints to use is done via $^H. Peeking at the hints in effect can be done using caller.
The hints are lexically scoped in the parser in order to make the effects of this pragma lexically scoped too.
$ perl -E'
my @hints = ( [refs=>0x2], [subs=>0x200], [vars=>0x400] );
sub hints {
my $h = (caller(0))[8];
my @h = map { $h & $_->[1] ? $_->[0] : () } @hints;
@h ? join(",", @h) : "[none]"
}
say hints; # [none]
use strict;
say hints; # refs,subs,vars
{
say hints; # refs,subs,vars
no strict;
say hints; # [none]
}
say hints; # refs,subs,vars
'
[none]
refs,subs,vars
refs,subs,vars
[none]
refs,subs,vars
|