- localization takes place and not when "localize" is called. This
- means that
-
- sub tag { localize '$x', $_[0] => 1; }
-
- will localize in the caller's namespace.
-
- "localize_elem $what, $key, $value, $level"
- Similar to "localize" but for array and hash elements. If $what is a
- glob, the slot to fill is determined from which type of reference $value
- is ; otherwise it's inferred from the sigil. $key is either an array
- index or a hash key, depending of which kind of variable you localize.
-
- "localize_delete $what, $key, $level"
- Similiar to "localize", but for deleting variables or array/hash
- elements. $what can be:
+ localization takes place and not when "localize" is called. Thus, if
+ the symbol name is not qualified, it will refer to the variable in
+ the package where the localization actually takes place and not in
+ the one where the "localize" call was compiled. For example,
+
+ {
+ package Scope;
+ sub new { localize '$tag', $_[0] => UP }
+ }
+
+ {
+ package Tool;
+ {
+ Scope->new;
+ ...
+ }
+ }
+
+ will localize $Tool::tag and not $Scope::tag. If you want the other
+ behaviour, you just have to specify $what as a glob or a qualified
+ name.
+
+ Note that if $what is a string denoting a variable that wasn't
+ declared beforehand, the relevant slot will be vivified as needed
+ and won't be deleted from the glob when the localization ends. This
+ situation never arises with "local" because it only compiles when
+ the localized variable is already declared. Although I believe it
+ shouldn't be a problem as glob slots definedness is pretty much an
+ implementation detail, this behaviour may change in the future if
+ proved harmful.
+
+ "localize_elem $what, $key, $value, $context"
+ Introduces a "local $what[$key] = $value" or "local $what{$key} =
+ $value" delayed to the time of first return into the upper scope denoted
+ by $context. Unlike "localize", $what must be a string and the type of
+ localization is inferred from its sigil. The two only valid types are
+ array and hash ; for anything besides those, "localize_elem" will throw
+ an exception. $key is either an array index or a hash key, depending of
+ which kind of variable you localize.
+
+ If $what is a string pointing to an undeclared variable, the variable
+ will be vivified as soon as the localization occurs and emptied when it
+ ends, although it will still exist in its glob.
+
+ "localize_delete $what, $key, $context"
+ Introduces the deletion of a variable or an array/hash element delayed
+ to the time of first return into the upper scope denoted by $context.
+ $what can be: