# Immediately return (1, 2, 3) from the sub, bypassing the eval.
$sub->unwind(@values, 3);
# 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
}
=head1 DESCRIPTION
@@ -70,17+77,20 @@ This gives you a prettier and safer interface when you are not reaching for extr
The L<Scope::Context> methods actually do more than their subroutine counterparts from L<Scope::Upper> : 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 :
The L<Scope::Context> methods actually do more than their subroutine counterparts from L<Scope::Upper> : 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</reap> is called.
=head1 METHODS
will croak when L</reap> is called.
=head1 METHODS
-=head2 C<new [ $context ]>
+=head2 C<new>
+
+ my $cxt = Scope::Context->new;
+ my $cxt = Scope::Context->new($scope_upper_cxt);
Creates a new immutable L<Scope::Context> object from the L<Scope::Upper>-comptabile context C<$context>.
If omitted, C<$context> defaults to the current context.
Creates a new immutable L<Scope::Context> object from the L<Scope::Upper>-comptabile context C<$context>.
If omitted, C<$context> defaults to the current context.
Returns the Perl context (in the sense of C<wantarray> : C<undef> for void context, C<''> for scalar context, and true for list context) in which is executed the scope corresponding to the topic L<Scope::Context> object.
=cut
Returns the Perl context (in the sense of C<wantarray> : C<undef> for void context, C<''> for scalar context, and true for list context) in which is executed the scope corresponding to the topic L<Scope::Context> object.
Executes the code reference C<$code> with arguments C<@args> in the same setting as the closest subroutine enclosing the topic context, then returns to the current scope the values returned by C<$code>.
Executes the code reference C<$code> with arguments C<@args> in the same setting as the closest subroutine enclosing the topic context, then returns to the current scope the values returned by C<$code>.