The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Devel::Unwind - What if you could die to a labeled eval?

SYNOPSIS

    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;
    }

DESCRIPTION

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.

AUTHORS

Andreas Guðmundsson andreasg@cpan.org