X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FScope%2FUpper.pm;h=6ca286c47db5955d27f0f186b2443d06f56eacaa;hb=4883814802ce13b05c096fdeefe987723fc3902f;hp=f4d43e7dfa04bd67171193f9b0d9dbb0d09f6b45;hpb=ca50ad37afae0c65ddc432c03f68d5cefae4de29;p=perl%2Fmodules%2FScope-Upper.git diff --git a/lib/Scope/Upper.pm b/lib/Scope/Upper.pm index f4d43e7..6ca286c 100644 --- a/lib/Scope/Upper.pm +++ b/lib/Scope/Upper.pm @@ -170,7 +170,7 @@ localize variables, array/hash values or deletions of elements in higher context =item * -return values immediately to an upper level with L, and know which context was in use then with L ; +return values immediately to an upper level with L, L and L, and know which context was in use then with L ; =item * @@ -316,14 +316,46 @@ This means that will set C<$num> to C<'z'>. You can use L to handle these cases. +=head2 C + + yield; + yield @values, $context; + +Returns C<@values> I the context pointed by or just above C<$context>, and immediately restart the program flow at this point. +If C<@values> is empty, then the C<$context> parameter is optional and defaults to the current context ; otherwise it is mandatory. + +L differs from L in that it can target I upper scope (besides a C substitution context) and not necessarily a sub, an eval or a format. +Hence you can use it to return values from a C or a C block : + + my $now = do { + local $@; + eval { require Time::HiRes } or yield time() => HERE; + Time::HiRes::time(); + }; + + my @uniq = map { + yield if $seen{$_}++; # returns the empty list from the block + ... + } @things; + +Like for L, the upper context isn't coerced onto C<@values>. + +=head2 C + + leave; + leave @values; + +Immediately returns C<@values> from the current block, whatever it may be (besides a C substitution context). +C is actually a synonym for C, while C is a synonym for C. + =head2 C my $want = want_at; my $want = want_at $context; -Like C, but for the subroutine/eval/format at or just above C<$context>. +Like L, but for the subroutine, eval or format context located at or just above C<$context>. -The previous example can then be "corrected" : +It can be used to revise the example showed in L : my $num = sub { my @a = ('a' .. 'z'); @@ -591,13 +623,14 @@ Where L, L and L act depending on t # $cxt = SCOPE(4), UP SUB UP SUB = UP SUB EVAL = UP CALLER(2) = TOP ... -Where L, L and L point to depending on the C<$cxt>: +Where L, L, L and L point to depending on the C<$cxt>: sub { eval { sub { { - unwind @things => $cxt; # or uplevel { ... } $cxt; + unwind @things => $cxt; # or yield @things => $cxt + # or uplevel { ... } $cxt ... } ... @@ -613,7 +646,7 @@ Where L, L and L point to depending on the C<$cxt>: =head1 EXPORT -The functions L, L, L, L, L, L and L are only exported on request, either individually or by the tags C<':funcs'> and C<':all'>. +The functions L, L, L, L, L, L, L, L and L are only exported on request, either individually or by the tags C<':funcs'> and C<':all'>. The constant L is also only exported on request, individually or by the tags C<':consts'> and C<':all'>. @@ -628,7 +661,8 @@ our %EXPORT_TAGS = ( funcs => [ qw< reap localize localize_elem localize_delete - unwind want_at + unwind yield leave + want_at uplevel uid validate_uid > ], @@ -692,7 +726,12 @@ Despite this shortcoming, this XS version of L should still run way fa =head1 DEPENDENCIES -L (standard since perl 5.006). +L 5.6. + +A C compiler. +This module may happen to build with a C++ compiler as well, but don't rely on it, as no guarantee is made in this regard. + +L (core since perl 5.006). =head1 SEE ALSO