Revision history for Scope-Upper
+0.02 2008-12-28 18:40 UTC
+ + Doc : Clarifications and improvements.
+ + Fix : Missing compatibility macros.
+ + Fix : Localized nonexistant array elements should be deleted when
+ their time comes so that the array recovers its original length.
+
0.01 2008-12-26 16:05 UTC
First version, released on an unsuspecting world.
Scope::Upper - Act on upper scopes.
VERSION
- Version 0.01
+ Version 0.02
SYNOPSIS
package X;
to 1.
* A string beginning with a sigil, representing the symbol to localize
- and assign to. If the sigil is '$', then $value isn't dereferenced,
- that is
+ and to assign to. If the sigil is '$', "localize" follows the same
+ syntax as "local $x = $value", i.e. $value isn't dereferenced. For
+ example,
localize '$x', \'foo' => 0;
- will set $x to a reference to the string 'foo'. Other sigils behave
- as if a glob was passed.
+ will set $x to a reference to the string 'foo'. Other sigils ('@',
+ '%', '&' and '*') require $value to be a reference of the
+ corresponding type.
- The symbol is resolved when the actual localization takes place and
- not when "localize" is called. This means that
+ When the symbol is given by a string, it is resolved when the actual
+ localization takes place and not when "localize" is called. This
+ means that
sub tag { localize '$x', $_[0] => 1; }
only exported on request, either individually or by the tags ':funcs'
and ':all'.
+CAVEATS
+ Be careful that local variables are restored in the reverse order in
+ which they were localized. Consider those examples:
+
+ local $x = 0;
+ {
+ reap sub { print $x } => 0;
+ local $x = 1;
+ ...
+ }
+ # prints '0'
+ ...
+ {
+ local $x = 1;
+ reap sub { $x = 2 } => 0;
+ ...
+ }
+ # $x is 0
+
+ The first case is "solved" by moving the "local" before the "reap", and
+ the second by using "localize" instead of "reap".
+
+ "reap", "localize" and "localize_elem" effects can't cross "BEGIN"
+ blocks, hence calling those functions in "import" is deemed to be
+ useless. This is an hopeless case because "BEGIN" blocks are executed
+ once while localizing constructs should do their job at each run.
+
DEPENDENCIES
XSLoader (standard since perl 5.006).
perldoc Scope::Upper
+ Tests code coverage report is available at
+ <http://www.profvince.com/perl/cover/Scope-Upper>.
+
ACKNOWLEDGEMENTS
Inspired by Ricardo Signes.