X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScope-Upper.git;a=blobdiff_plain;f=README;h=15bb1ec4605ba4544036305244a377a8aa8cc345;hp=1e4c0a492c7b05b0f55e66480fa01d57ce3d9f64;hb=HEAD;hpb=ef9df3bbd464ffac7b3308d923cd94ff67e98a11 diff --git a/README b/README index 1e4c0a4..1f7b09e 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME Scope::Upper - Act on upper scopes. VERSION - Version 0.21 + Version 0.34 SYNOPSIS "reap", "localize", "localize_elem", "localize_delete" and "WORDS" : @@ -157,7 +157,7 @@ DESCRIPTION * execute a subroutine in the setting of an upper subroutine stack frame with "uplevel" ; - * uniquely identify contextes with "uid" and "validate_uid". + * uniquely identify contexts with "uid" and "validate_uid". FUNCTIONS In all those functions, $context refers to the target scope. @@ -261,7 +261,7 @@ FUNCTIONS "local *x". * A string beginning with '@' or '%', for which the call is equivalent - to respectiveley "local $a[$key]; delete $a[$key]" and "local + to respectively "local $a[$key]; delete $a[$key]" and "local $h{$key}; delete $h{$key}". * A string beginning with '&', which more or less does "undef &func" @@ -564,27 +564,35 @@ WORDS Getting a context from a context For any of those functions, $from is expected to be a context. When - omitted, it defaults to the the current context. + omitted, it defaults to the current context. "UP" my $upper_context = UP; my $upper_context = UP $from; - The context of the scope just above $from. + The context of the scope just above $from. If $from points to the + top-level scope in the current stack, then a warning is emitted and + $from is returned (see "DIAGNOSTICS" for details). "SUB" my $sub_context = SUB; my $sub_context = SUB $from; - The context of the closest subroutine above $from. Note that $from is - returned if it is already a subroutine context ; hence "SUB SUB == SUB". + The context of the closest subroutine above $from. If $from already + designates a subroutine context, then it is returned as-is ; hence "SUB + SUB == SUB". If no subroutine context is present in the call stack, then + a warning is emitted and the current context is returned (see + "DIAGNOSTICS" for details). "EVAL" my $eval_context = EVAL; my $eval_context = EVAL $from; - The context of the closest eval above $from. Note that $from is returned - if it is already an eval context ; hence "EVAL EVAL == EVAL". + The context of the closest eval above $from. If $from already designates + an eval context, then it is returned as-is ; hence "EVAL EVAL == EVAL". + If no eval context is present in the call stack, then a warning is + emitted and the current context is returned (see "DIAGNOSTICS" for + details). Getting a context from a level Here, $level should denote a number of scopes above the current one. @@ -595,7 +603,10 @@ WORDS my $context = SCOPE; my $context = SCOPE $level; - The $level-th upper context, regardless of its type. + The $level-th upper context, regardless of its type. If $level points + above the top-level scope in the current stack, then a warning is + emitted and the top-level context is returned (see "DIAGNOSTICS" for + details). "CALLER" my $context = CALLER; @@ -604,7 +615,9 @@ WORDS The context of the $level-th upper subroutine/eval/format. It kind of corresponds to the context represented by "caller $level", but while e.g. "caller 0" refers to the caller context, "CALLER 0" will refer to - the top scope in the current context. + the top scope in the current context. If $level points above the + top-level scope in the current stack, then a warning is emitted and the + top-level context is returned (see "DIAGNOSTICS" for details). Examples Where "reap" fires depending on the $cxt : @@ -669,6 +682,20 @@ WORDS # (*) Note that uplevel() will croak if you pass that scope frame, # because it cannot target eval scopes. +DIAGNOSTICS + "Cannot target a scope outside of the current stack" + This warning is emitted when "UP", "SCOPE" or "CALLER" end up pointing + to a context that is above the top-level context of the current stack. + It indicates that you tried to go higher than the main scope, or to + point across a "DESTROY" method, a signal handler, an overloaded or tied + method call, a "require" statement or a "sort" callback. In this case, + the resulting context is the highest reachable one. + + "No targetable %s scope in the current stack" + This warning is emitted when you ask for an "EVAL" or "SUB" context and + no such scope can be found in the call stack. The resulting context is + the current one. + EXPORT The functions "reap", "localize", "localize_elem", "localize_delete", "unwind", "yield", "leave", "want_at", "context_info" and "uplevel" are @@ -683,6 +710,11 @@ EXPORT ':words' and ':all'. CAVEATS + It is not possible to act upon a scope that belongs to another perl + 'stack', i.e. to target a scope across a "DESTROY" method, a signal + handler, an overloaded or tied method call, a "require" statement or a + "sort" callback. + Be careful that local variables are restored in the reverse order in which they were localized. Consider those examples: @@ -730,20 +762,25 @@ CAVEATS Moreover, in order to handle "goto" statements properly, "uplevel" currently has to suffer a run-time overhead proportional to the size of - the the callback in every case (with a small ratio), and proportional to - the size of all the code executed as the result of the "uplevel" call + the callback in every case (with a small ratio), and proportional to the + size of all the code executed as the result of the "uplevel" call (including subroutine calls inside the callback) when a "goto" statement is found in the "uplevel" callback. Despite this shortcoming, this XS version of "uplevel" should still run way faster than the pure-Perl version from Sub::Uplevel. + Starting from "perl" 5.19.4, it is unfortunately no longer possible to + reliably throw exceptions from "uplevel"'d code while the debugger is in + use. This may be solved in a future version depending on how the core + evolves. + DEPENDENCIES - perl 5.6. + perl 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. - XSLoader (core since perl 5.006). + XSLoader (core since perl 5.6.0). SEE ALSO "local" in perlfunc, "Temporary Values via local()" in perlsub. @@ -760,7 +797,7 @@ SEE ALSO Scope::Escape. AUTHOR - Vincent Pit, "", . + Vincent Pit "". You can contact me by mail or on "irc.perl.org" (vincent). @@ -776,16 +813,19 @@ SUPPORT perldoc Scope::Upper - Tests code coverage report is available at - . - ACKNOWLEDGEMENTS Inspired by Ricardo Signes. + The reimplementation of a large part of this module for perl 5.24 was + provided by David Mitchell. His work was sponsored by the Perl 5 Core + Maintenance Grant from The Perl Foundation. + Thanks to Shawn M. Moore for motivation. COPYRIGHT & LICENSE - Copyright 2008,2009,2010,2011,2012 Vincent Pit, all rights reserved. + Copyright + 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2021,2023 + 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.