OUTER::<$varname> (S06, "Out-of-scope names")
$OUTER::varname (S02, "Names")
specifies the $varname declared in the lexical scope surrounding the current
lexical scope (i.e. the scope in which the current block was defined).
sub outersub ()
{
my $a;
my $b;
my $closure = sub {
say $a; # OK, that's what closures do.
say $OUTER::a; # same thing
say $OUTER::("b"); # symbolic reference
}
my &Pascalishsub := sub ($cl)
{
$cl(); # CALL 2
}
$closure(); # CALL 1
Pascalishsub($closure); # prelude to CALL 2
return $closure; # prelude to CALL 3
}
my $cl = outersub;
$cl(); # CALL 3
What happens? The OUTER scope no longer exists at CALL 3. Does a symbolic
reference to OUTER require that the entire scope be retained, just in case? If
"OUTER" itself (or OUTER::OUTER::...) is symbolic, it would need to remember
everything always, just in case.
Yet in CALL 1, the use of OUTER makes sense, and is a normal use. This
situation should be allowed, or you'll have a hard time describing exactly when
OUTER may be used symbolically, since the simple description now is that all
blocks are closures, but most can be optomized down.
Now look at CALL 2. The situation is similar in that the outer scope still
exists, but it is much harder for OUTER to figure out where to look. Does this
work? If not, again, its hard to explain just when it should or shouldn't,
because cases that do are just automatic degenerate forms of "every block is a
closure".
--John