Scope::Upper - Act on upper scopes.
VERSION
- Version 0.07
+ Version 0.10
SYNOPSIS
package X;
sub zap {
try {
return @things; # returns to try() and then outside zap()
+ # not reached
}
+ # not reached
}
my @what = zap(); # @what contains @things
needed, and it will still denote the original scope.
"reap $callback, $context"
- Add a destructor that calls $callback when the upper scope represented
- by $context ends.
+ Add a destructor that calls $callback (in void context) when the upper
+ scope represented by $context ends.
"localize $what, $value, $context"
A "local" delayed to the time of first return into the upper scope
my $num = sub {
my @a = ('a' .. 'z');
unwind @a => HERE;
+ # not reached
}->();
will set $num to 'z'. You can use "want_at" to handle these cases.
my $num = sub {
my @a = ('a' .. 'z');
unwind +(want_at(HERE) ? @a : scalar @a) => HERE;
+ # not reached
}->();
- will righteously set $num to 26.
+ will rightfully set $num to 26.
+
+CONSTANTS
+ "SU_THREADSAFE"
+ True iff the module could have been built when thread-safety features.
WORDS
Constants
"unwind" and "want_at" are only exported on request, either individually
or by the tags ':funcs' and ':all'.
+ The constant "SU_THREADSAFE" is also only exported on request,
+ individually or by the tags ':consts' and ':all'.
+
Same goes for the words "TOP", "HERE", "UP", "SUB", "EVAL", "SCOPE" and
"CALLER" that are only exported on request, individually or by the tags
':words' and ':all'.
SEE ALSO
Alias, Hook::Scope, Scope::Guard, Guard.
+ Continuation::Escape is a thin wrapper around Scope::Upper that gives
+ you a continuation passing style interface to "unwind". It's easier to
+ use, but it requires you to have control over the scope where you want
+ to return.
+
AUTHOR
Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
Thanks to Shawn M. Moore for motivation.
COPYRIGHT & LICENSE
- Copyright 2008-2009 Vincent Pit, all rights reserved.
+ Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.