PrePAN

Sign in to PrePAN

Die::Eventually Gathers multiple deaths - in scope - to be executed going out of scope

Author
torbjorn@github
Date
URL
Status
In Review
Good

Synopsis

use Die::Eventually;

sub foo {

    die_soon "this is wrong" unless some_test();

    execute_some_code();

    die_soon "this also isnt right" unless some_other_test();

}

foo(); # dies with those two messages above

Description

The idea is to avoid this pattern:

my @errors;

push @errors, "foo" if bar();

push @errors, "bar" if baz();

die join "\n", @errors if @errors;

It's not a dramatic reduction in code lines, but it is a nice reduction in programmer brain usage on mundane everyday boring things.

Comments

The idea is motivated, and the implementation will probably be influenced by, Lexical::Failure::Objects, though that module doesn't quite fit (but would if it could had a mechanic for stacking errors), and otherwise is perhaps a bit much.

Please sign up to post a review.