Devel::Unwind - What if you could die to a labeled eval?
use Devel::Unwind; $SIG{__DIE__} = sub { print "I die: @_" }; mark FOO { unwind FOO; }; mark FOO { unwind FOO "foobar"; 1; } or do { print "or do: $@"; }; mark FOO { unwind FOO 1..5; }; package BAR { sub PROPAGATE {print "I propagate: @_\n"; $_[0]->[0]} } mark FOO { $@ = bless ["baz"], "BAR"; unwind FOO; }
Imagine Perl had the ability to die to a labeled eval so that when you write
FOO: eval {...}
you could die to that labeled eval
die FOO "bar";
That is essentially what Devel::Unwind gives you. Two custom keywords 'mark','unwind' are added allowing you two write
use Devel::Unwind; mark FOO {...} or do {...} unwind FOO "bar"; unwind FOO "bar","baz"; unwind FOO (bless [], "Bar"); unwind FOO;
Wherever you would put a block 'eval' an 'mark' expression can be used. And wherever you would 'die' you can 'unwind'. If a $SIG{__DIE__} handler is installed then it gets called on 'unwind'. The arguments to 'unwind' are treated the same way as the arguments to 'die'. Multiple arguments are joined to togeter, a single argument is passed through untouched unless it is a object with PROPAGATE method in which case $@ gets replaced by the return value of that method. For details read the documentation of die.
Andreas Guðmundsson andreasg@cpan.org
andreasg@cpan.org
To install Devel::Unwind, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::Unwind
CPAN shell
perl -MCPAN -e shell install Devel::Unwind
For more information on module installation, please visit the detailed CPAN module installation guide.