Author: larry
Date: Sat Mar 10 21:59:07 2007
New Revision: 14330
Modified:
doc/trunk/design/syn/S04.pod
doc/trunk/design/syn/S06.pod
Log:
More fiddling with context().
Modified: doc/trunk/design/syn/S04.pod
==============================================================================
--- doc/trunk/design/syn/S04.pod (original)
+++ doc/trunk/design/syn/S04.pod Sat Mar 10 21:59:07 2007
@@ -690,9 +690,9 @@
caller.leave(1,2,3)
Further contexts up the caller stack may be located by the selector
-that is built into the C<caller> function itself:
+that is built into the C<context> function itself:
- caller({ .label eq 'LINE' }).leave(1,2,3);
+ context(0, { .label eq 'LINE' }).leave(1,2,3);
By default the innermost dynamic scope matching the selection criteria
will be exited. This can be a bit cumbersome, so in the particular
@@ -729,7 +729,7 @@
control structures, hence the sub's lexical scope was I<always>
the innermost dynamic scope, so the preference to the lexical scope
in the current sub was implicit. For PerlĀ 6 we have to make this
-preference explicit.) So this fallback is more like the C<caller>
+preference explicit.) So this fallback is more like the C<context>
form we saw earlier.
Warnings are produced in PerlĀ 6 by throwing a resumable control
Modified: doc/trunk/design/syn/S06.pod
==============================================================================
--- doc/trunk/design/syn/S06.pod (original)
+++ doc/trunk/design/syn/S06.pod Sat Mar 10 21:59:07 2007
@@ -1690,7 +1690,7 @@
The C<caller> function is defined as
- &caller ::= &context.assuming(1);
+ &caller ::= &context.assuming(1, *);
so the preceding example can also be written:
@@ -1713,10 +1713,11 @@
$ctx = context($i); # $i'th caller's context
The second argument is optional and is a matcher to apply against the
-context object.
+context object. The first argument only counts matching contexts:
$ctx = context(0, Method); # nearest context that is method
$ctx = context(1, Method); # 2nd nearest context that is method
+ $ctx = context(1, Method).caller; # caller of that 2nd nearest method
$ctx = context(0, Block); # nearest context that is block
$ctx = context(2, Sub); # 3rd nearest sub context
$ctx = context(0, Block where { .label eq 'Foo' });
@@ -1729,20 +1730,27 @@
which returns the context of the innermost Foo block in the lexical scope
rather than the dynamic scope.
-The returned context object has the following methods:
+The returned context object supports at least the following methods:
.want
+ .context
+ .caller
.file
.line
.subname
+ .lookup
-and basically anything else defined as C<$?NAME> there. (XXX cop out)
+The C<.lookup> method provides access to the lexical namespace in effect
+at the given dynamic context's current position. It may be used to look
+up ordinary lexical variables as well as special compiler variables such
+as C<$?PACKAGE>. It must not be used to change any lexical variable
+that is not marked as C<< context<rw> >>.
=head2 The C<want> function
The C<want> function returns a C<Signature> object that contains information
about the context in which the current block, closure, or subroutine was
-called.
+called. The C<want> function is really just short for C<context(0).want>.
As with normal function signatures, you can test the result of C<want> with a
smart match (C<~~>) or a C<when>: