I've been making a lot of deploy scripts lately. They're the sort of thing where you run through a sequence of steps, and if any of the steps fail you want it to bail out and tell you what it failed on.
I know a lot of ways I *could* accomplish this goal. I could follow every statement with a die and the reason for the death:
{
foo() || die "foo() didn't return true";
bar() || die "bar() didn't return true";
... and so on
}
But really, the only thing that's significant is the calls to foo() and bar(). The dies are just stating information that's already there, if we give the block some context. I am pondering writing a source filter so that I can wrap every statement with an '|| die "$statement returned false!"', but this seems really dirty. Ideally I'd like a syntax like:
every { block of statements }
run { block to be run after each statement in 1st block }
So, to emulate the above example:
every {
foo();
bar();
...
}
run {
my $command = shift; # String representation of statement
my $result = shift; # What the statement returned
die "Command $command did not return true!" unless $result;
}
Am I crazy for even wanting something like this? Is there something out there that can accomplish the goals of syntactic simplicity (not burdening the straight sequence of statements with extra baggage) while still giving the ability to do something after each statement?
-- KILNA - music for cyborgs - http://www.kilna.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.