+WORDS
+ Constants
+ "TOP"
+ my $top_context = TOP;
+
+ Returns the context that currently represents the highest scope.
+
+ "HERE"
+ my $current_context = HERE;
+
+ The context of the current scope.
+
+ Getting a context from a context
+ For any of those functions, $from is expected to be a context. When
+ 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. 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. 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. 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.
+ When omitted, it defaults to 0 and those functions return the same
+ context as "HERE".
+
+ "SCOPE"
+ my $context = SCOPE;
+ my $context = SCOPE $level;
+
+ 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;
+ my $context = CALLER $level;
+
+ 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. 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 :
+
+ sub {
+ eval {
+ sub {
+ {
+ reap \&cleanup => $cxt;
+ ...
+ } # $cxt = SCOPE(0) = HERE
+ ...
+ }->(); # $cxt = SCOPE(1) = UP = SUB = CALLER(0)
+ ...
+ }; # $cxt = SCOPE(2) = UP UP = UP SUB = EVAL = CALLER(1)
+ ...
+ }->(); # $cxt = SCOPE(3) = SUB UP SUB = SUB EVAL = CALLER(2)
+ ...
+
+ Where "localize", "localize_elem" and "localize_delete" act depending on
+ the $cxt :
+
+ sub {
+ eval {
+ sub {
+ {
+ localize '$x' => 1 => $cxt;
+ # $cxt = SCOPE(0) = HERE
+ ...
+ }
+ # $cxt = SCOPE(1) = UP = SUB = CALLER(0)
+ ...
+ }->();
+ # $cxt = SCOPE(2) = UP UP = UP SUB = EVAL = CALLER(1)
+ ...
+ };
+ # $cxt = SCOPE(3) = SUB UP SUB = SUB EVAL = CALLER(2)
+ ...
+ }->();
+ # $cxt = SCOPE(4), UP SUB UP SUB = UP SUB EVAL = UP CALLER(2) = TOP
+ ...
+
+ Where "unwind", "yield", "want_at", "context_info" and "uplevel" point
+ to depending on the $cxt:
+
+ sub {
+ eval {
+ sub {
+ {
+ unwind @things => $cxt; # or yield @things => $cxt
+ # or uplevel { ... } $cxt
+ ...
+ }
+ ...
+ }->(); # $cxt = SCOPE(0) = SCOPE(1) = HERE = UP = SUB = CALLER(0)
+ ...
+ }; # $cxt = SCOPE(2) = UP UP = UP SUB = EVAL = CALLER(1) (*)
+ ...
+ }->(); # $cxt = SCOPE(3) = SUB UP SUB = SUB EVAL = CALLER(2)
+ ...
+
+ # (*) 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.