From: Vincent Pit Date: Fri, 11 Nov 2011 21:01:29 +0000 (+0100) Subject: Clarify some examples X-Git-Tag: v0.02~16 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=009a63ef9c222e154654b0df6e3dcda9cf375d21;p=perl%2Fmodules%2FScope-Context.git Clarify some examples --- diff --git a/lib/Scope/Context.pm b/lib/Scope/Context.pm index 7bf5c8c..4f327a3 100644 --- a/lib/Scope/Context.pm +++ b/lib/Scope/Context.pm @@ -29,7 +29,7 @@ our $VERSION = '0.01'; for (1 .. 5) { sub { eval { - # create Scope::Context objects + # Create Scope::Context objects for different upper frames. my ($block, $sub, $eval, $loop); { $block = Scope::Context->new; @@ -46,7 +46,7 @@ our $VERSION = '0.01'; # This prints "hello" when the eval block above ends. $eval->reap(sub { print "hello\n" }); - # Ignore $SIG{__DIE__} just for the loop. + # Ignore $SIG{__DIE__} just for the loop body. $loop->localize_delete('%SIG', '__DIE__'); # Execute the callback as if it ran in place of the sub. @@ -56,8 +56,15 @@ our $VERSION = '0.01'; # Immediately return (1, 2, 3) from the sub, bypassing the eval. $sub->unwind(@values, 3); + + # Not reached. } + + # Not reached. }->(); + + # unwind() returns here. "hello\n" was printed, and now + # $SIG{__DIE__} is undefined. } =head1 DESCRIPTION @@ -70,11 +77,11 @@ This gives you a prettier and safer interface when you are not reaching for extr The L methods actually do more than their subroutine counterparts from L : before each call, the target context will be checked to ensure it is still active (which means that it is still present in the current call stack), and an exception will be thrown if you attempt to act on a context that has already expired. This means that : - my $sc; + my $cxt; { - $sc = Scope::Context->new; + $cxt = Scope::Context->new; } - $sc->reap(sub { print "hello\n }); + $cxt->reap(sub { print "hello\n }); will croak when L is called. @@ -241,7 +248,7 @@ If omitted, C<$frames> defaults to C<0>, which results in the closest sub enclos } sub inner { - my $sub = Scope::Context->new->sub(1); # = Scope::Context->sub + my $sub = Scope::Context->new->sub(1); # = Scope::Context->sub(1) # $sub points to the context for the outer() sub. }