X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FScope%2FUpper.pm;h=a78272700766875a4fb2b63d29a43f12704dddfb;hb=832f6a4eae21bec85e1cb1043fbc41fcf59cbfcd;hp=4a9010059f7ce5112af17d57452539ae17458ff8;hpb=be1d59463692da1b5ef787aeffd0aedbef65664e;p=perl%2Fmodules%2FScope-Upper.git diff --git a/lib/Scope/Upper.pm b/lib/Scope/Upper.pm index 4a90100..a782727 100644 --- a/lib/Scope/Upper.pm +++ b/lib/Scope/Upper.pm @@ -9,13 +9,13 @@ Scope::Upper - Act on upper scopes. =head1 VERSION -Version 0.19 +Version 0.21 =cut our $VERSION; BEGIN { - $VERSION = '0.19'; + $VERSION = '0.21'; } =head1 SYNOPSIS @@ -170,7 +170,11 @@ localize variables, array/hash values or deletions of elements in higher context =item * -return values immediately to an upper level with L, L and L, and know which context was in use then with L ; +return values immediately to an upper level with L, L and L ; + +=item * + +gather information about an upper context with L and L ; =item * @@ -301,7 +305,7 @@ C<$key> is ignored. unwind; unwind @values, $context; -Returns C<@values> I the subroutine, eval or format context pointed by or just above C<$context>, and immediately restart the program flow at this point - thus effectively returning C<@values> to an upper scope. +Returns C<@values> I the subroutine, eval or format context pointed by or just above C<$context>, and immediately restarts the program flow at this point - thus effectively returning C<@values> to an upper scope. If C<@values> is empty, then the C<$context> parameter is optional and defaults to the current context (making the call equivalent to a bare C) ; otherwise it is mandatory. The upper context isn't coerced onto C<@values>, which is hence always evaluated in list context. @@ -321,7 +325,7 @@ You can use L to handle these cases. 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. +Returns C<@values> I the context pointed by or just above C<$context>, and immediately restarts 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. @@ -339,6 +343,7 @@ Hence you can use it to return values from a C or a C block : } @things; Like for L, the upper context isn't coerced onto C<@values>. +You can use the fifth value returned by L to handle context coercion. =head2 C @@ -346,16 +351,18 @@ Like for L, the upper context isn't coerced onto C<@values>. 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. +C is actually a synonym for C, while C is a synonym for C. + +Like for L, you can use the fifth value returned by L to handle context coercion. =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'); @@ -365,6 +372,65 @@ The previous example can then be "corrected" : will rightfully set C<$num> to C<26>. +=head2 C + + my ($package, $filename, $line, $subroutine, $hasargs, + $wantarray, $evaltext, $is_require, $hints, $bitmask, + $hinthash) = context_info $context; + +Gives information about the context denoted by C<$context>, akin to what L provides but not limited only to subroutine, eval and format contexts. +When C<$context> is omitted, it defaults to the current context. + +The returned values are, in order : + +=over 4 + +=item * + +I<(index 0)> : the namespace in use when the context was created ; + +=item * + +I<(index 1)> : the name of the file at the point where the context was created ; + +=item * + +I<(index 2)> : the line number at the point where the context was created ; + +=item * + +I<(index 3)> : the name of the subroutine called for this context, or C if this is not a subroutine context ; + +=item * + +I<(index 4)> : a boolean indicating whether a new instance of C<@_> was set up for this context, or C if this is not a subroutine context ; + +=item * + +I<(index 5)> : the context (in the sense of L) in which the context (in our sense) is executed ; + +=item * + +I<(index 6)> : the contents of the string being compiled for this context, or C if this is not an eval context ; + +=item * + +I<(index 7)> : a boolean indicating whether this eval context was created by C, or C if this is not an eval context ; + +=item * + +I<(index 8)> : the value of the lexical hints in use when the context was created ; + +=item * + +I<(index 9)> : a bit string representing the warnings in use when the context was created ; + +=item * + +I<(index 10)> : a reference to the lexical hints hash in use when the context was created (only on perl 5.10 or greater). + +=back + =head2 C my @ret = uplevel { ...; return @ret }; @@ -623,7 +689,7 @@ 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, L and L point to depending on the C<$cxt>: +Where L, L, L, L and L point to depending on the C<$cxt>: sub { eval { @@ -646,7 +712,7 @@ Where L, L, L and L point to depending on t =head1 EXPORT -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 functions L, 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'>. @@ -662,7 +728,7 @@ our %EXPORT_TAGS = ( reap localize localize_elem localize_delete unwind yield leave - want_at + want_at context_info uplevel uid validate_uid > ], @@ -726,7 +792,7 @@ Despite this shortcoming, this XS version of L should still run way fa =head1 DEPENDENCIES -L 5.6. +L 5.6.1. 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.