It's not require
that's interesting; it's what the pragma does in import
.
Most (all?) pragmas use $^H
or %^H
. The parser localises these to the scope being parsed, meaning it restores them to the value they had before
Take strict, for example. Its import
modifies $^H
. $^H
contains a series of flags that instructs the compiler how to behave.
$ perl -e'
BEGIN { printf "%04X\n", $^H }
{
use strict;
BEGIN { printf "%04X\n", $^H }
}
BEGIN { printf "%04X\n", $^H }
'
0100
0702
0100
$^H
is reserved for Perl's usage, but similarly localised %^H
is available for general use. For example, feature::qw_comment hooks into the parser once, when it's loaded by require
, but doesn't do anything unless $^H{'feature::qw_comments::'}
is true. It's import is equivalent to
sub import { $^H{'feature::qw_comments::'} = 1; }