Scriptalicious Perl module can make scripts more delicious to SysAdmins.
-progname => "pu";
our $VERSION = "1.00";
my $url = ".";
getopt getconf("u|url" => $url);
run("echo", "doing something with $url");
my $output = capture("svn", "info", $url);
pu - an uncarved block of wood
pu [options] arguments
This script's function is to be a blank example that many
great and simple scripts may be built upon.
Remember, you cannot carve rotten wood.
=head1 COMMAND LINE OPTIONS
=item B< -h, --help >
Display a program usage screen and exit.
=item B< -V, --version >
Display program version and exit.
=item B< -v, --verbose >
Verbose command execution, displaying things like the
commands run, their output, etc.
=item B< -q, --quiet >
Suppress all normal program output; only display errors and
=item B< -d, --debug >
Display output to help someone debug this script, not the
process going on.
This module helps you write scripts that conform to best common practices, quickly. Just include the above as a template, and your script will accept all of the options that are included in the manual page, as well as summarising them when you use the -h option.
(Unfortunately, it is not possible to have a `use' dependency automatically add structure to your POD yet, so you have to include the above manually. If you want your help message and Perldoc to be meaningful, that is.)
Shortcuts are provided to help you abort or die with various error conditions; all of which print the name of the program running (taken from $0 if not passed). The motive for this is that "small" scripts tend to just get written and forgotten; so, when you have a larger system that is built out of lots of these pieces it is sometimes guesswork figuring out which script a printed message comes from!
For instance, if your program is called with invalid arguments, you may simply call abort with a one-line message saying what the particular problem was. When the script is run, it will invite the person running the script to try to use the --help option, which gives them a summary and in turn invites them to read the Perldoc. So, it reads well in the source;
@ARGV and abort "unexpected arguments: @ARGV";
$file or abort "no filename supplied";
And in the output;
somescript: no filename supplied!
Try `somescript --help' for a summary of options
On the other hand, if you call barf, then it is considered to be a hard run-time failure, and the invitation to read the --help page to get usage not given. Also, the messages are much tidier than you get with die et al.
open FOO, "