On Thu, Mar 1, 2018 at 9:56 AM, David Cantrell <da...@cantrell.org.uk>
wrote:

>
> My approach is to have the script be mostly a wrapper around more
> easily-testable modules - the script just wrangles arguments and shows
> results.
>

+1 for that approach in general. Makes it easy to call the "useful" code in
the script in other places.

Something to do in small scripts which don't aren't module material, is to
put all the "useful" code into subs, put the command-line processing &
printing into a "sub MAIN", and then have only this top-level statement:

    exit MAIN unless caller;

That lets the script be called normally, executing when run from the
command line. On the other hand, another perl program can "require '
the_code_file.pl'" and load all the subs without anything executing- so
your test code can call MAIN after setting @ARGV to whatever it wants - or
can test the other subs as needed.

Reply via email to