]> git.vpit.fr Git - perl/modules/Scope-Context.git/blobdiff - lib/Scope/Context.pm
Fix an off-by-one description in POD
[perl/modules/Scope-Context.git] / lib / Scope / Context.pm
index aa422e1b950a8ecc682e3ff1b4863588aae82e7e..6658c3cfe8596208bdb09fd4ccca799230192cbf 100644 (file)
@@ -16,11 +16,11 @@ Scope::Context - Object-oriented interface for inspecting or acting upon upper s
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 SYNOPSIS
 
@@ -29,32 +29,33 @@ our $VERSION = '0.01';
     for (1 .. 5) {
      sub {
       eval {
-       # Create Scope::Context objects for different upper frames.
-       my ($block, $sub, $eval, $loop);
+       # Create Scope::Context objects for different upper frames :
+       my ($block, $eval, $sub, $loop);
        {
         $block = Scope::Context->new;
-        $sub   = $block->sub;    # = $block->up
-        $eval  = $block->eval;   # = $block->up(2)
-        $loop  = $eval->up;      # = $block->up(3)
+        $eval  = $block->eval;   # == $block->up
+        $sub   = $block->sub;    # == $block->up(2)
+        $loop  = $sub->up;       # == $block->up(3)
        }
 
        eval {
-        # This will throw an exception, since $block has expired.
+        # This throws an exception, since $block has expired :
         $block->localize('$x' => 1);
        };
 
-       # This prints "hello" when the eval block above ends.
+       # This will print "hello" when the current eval block ends :
        $eval->reap(sub { print "hello\n" });
 
-       # Ignore $SIG{__DIE__} just for the loop body.
-       $loop->localize_delete('%SIG', '__DIE__');
+       # Ignore warnings just for the loop body :
+       $loop->localize_elem('%SIG', __WARN__ => sub { });
 
-       # Execute the callback as if it ran in place of the sub.
+       # Execute the callback as if it ran in place of the sub :
        my @values = $sub->uplevel(sub {
         return @_, 2;
        }, 1);
+       # @values now contains (1, 2).
 
-       # Immediately return (1, 2, 3) from the sub, bypassing the eval.
+       # Immediately return (1, 2, 3) from the sub, bypassing the eval :
        $sub->unwind(@values, 3);
 
        # Not reached.
@@ -63,10 +64,13 @@ our $VERSION = '0.01';
       # Not reached.
      }->();
 
-     # unwind() returns here. "hello\n" was printed, and now
-     # $SIG{__DIE__} is undefined.
+     # unwind() returns here. "hello\n" was printed, and now warnings are
+     # ignored.
     }
 
+    # $SIG{__WARN__} has been restored to its original value, warnings are no
+    # longer ignored.
+
 =head1 DESCRIPTION
 
 This class provides an object-oriented interface to L<Scope::Upper>'s functionalities.
@@ -361,7 +365,7 @@ sub up {
     my $sub_cxt = $cxt->sub($frames);
     my $sub_cxt = Scope::Context->sub;
 
-Returns a new L<Scope::Context> object pointing to the C<$frames>-th subroutine scope above the scope pointed by the invocant.
+Returns a new L<Scope::Context> object pointing to the C<$frames + 1>-th subroutine scope above the scope pointed by the invocant.
 
 This method can also be invoked as a class method, in which case it is equivalent to calling L</sub> on a L<Scope::Context> object for the current context.
 
@@ -405,7 +409,7 @@ sub sub {
     my $eval_cxt = $cxt->eval($frames);
     my $eval_cxt = Scope::Context->eval;
 
-Returns a new L<Scope::Context> object pointing to the C<$frames>-th C<eval> scope above the scope pointed by the invocant.
+Returns a new L<Scope::Context> object pointing to the C<$frames + 1>-th C<eval> scope above the scope pointed by the invocant.
 
 This method can also be invoked as a class method, in which case it is equivalent to calling L</eval> on a L<Scope::Context> object for the current context.
 
@@ -597,7 +601,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2011,2012,2013 Vincent Pit, all rights reserved.
+Copyright 2011,2012,2013,2015 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.