Continuation::Escape - escape continuations (returning higher up the stack)
use Continuation::Escape; my $ret = call_cc { my $escape = shift; # ... sub { # ... $escape->(1 + 1); # code never reached }->(); # code never reached }; $ret # 2
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.
This module builds on Vincent Pit's excellent Scope::Upper to give you a nicer interface to returning to outer scopes.
If the return context of the continuation is scalar, the first argument to the continuation will be returned. This is slightly more useful than 1, the number of arguments to the continuation. This DWIMs when you want to return a scalar anyway.
1
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.
call_cc
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? :)
:)
Shawn M Moore, sartak@gmail.com
sartak@gmail.com
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).
Copyright 2009 Shawn M Moore.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Continuation::Escape, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Continuation::Escape
CPAN shell
perl -MCPAN -e shell install Continuation::Escape
For more information on module installation, please visit the detailed CPAN module installation guide.