Doing this with separate modules would not be the normal way to go in Perl. For one thing by tradition a module that returns 0 raises an exception. Instead I would suggest that you call a series of functions. That could be coded as simply as this:
sub do_each_until_false { for (@_) { return 0 unless $_->(); } return 1; }
and then called like this:
if ( do_each_until_false( \&function1, \&function2, sub {require Foo; Foo::bar()}, \&function3, # etc. ) ) { print "All done\n"; } else { print "FAILED\n"; }
However this is not really a significant win over just writing straight line code using a bare block:
my $is_success = 0; BLOCK: { function1() or last BLOCK; function2() or last BLOCK; require Foo; Foo::bar() or last BLOCK; function3() or last BLOCK; # etc; $is_success = 1; } if ($is_success) { print "All done\n"; } else { print "FAILED\n"; }
Particularly if you discover that some of your functions need to pass parameters in and out, or sometimes you need to store information from one function call to the next.

In reply to Re: Code for Control Module by tilly
in thread Code for Control Module by perlpal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.