Shawn M Moore > Continuation-Escape-0.02 > Continuation::Escape

Download:
Continuation-Escape-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.02   Source   Latest Release: Continuation-Escape-0.03

NAME ^

Continuation::Escape - escape continuations (returning higher up the stack)

VERSION ^

version 0.02

SYNOPSIS ^

    use Continuation::Escape;

    my $ret = call_cc {
        my $escape = shift;

        # ...
        sub {
            # ...
            $escape->(1 + 1);
            # code never reached
        }->();
        # code never reached
    };

    $ret # 2

NAME ^

An escape continuation is a limited type of continuation that only allows you to jump back up the stack. Invoking an escape continuation is a lot like throwing an exception, however escape continuations do not necessarily indicate exceptional circumstances.

The interface for context will probably change. Right now when squeezing a list into scalar context, the last element is used, instead of the usual squeezing into the number of elements in that list. In the meantime, just use the same context on the receiving end as the sending end.

This module builds on Vincent Pit's excellent Scope::Upper to give you a nicer interface to returning to outer scopes.

CAVEATS ^

Escape continuations are not real continuations. They are not re-invokable (meaning you only get to run them once) and they are not savable (once the call_cc block ends, calling the continuation it gave you is an error). This module goes to some length to ensure that you do not try to do either of these things.

Real continuations in Perl would require a lot of work. But damn would they be nice. Does anyone know how much work would even be involved? :)

AUTHOR ^

Shawn M Moore, sartak@bestpractical.com

THANKS TO ^

Vincent Pit for writing the excellent Scope::Upper which does two things that I've wanted forever (escape continuations and localizing variables at higher stack levels).