NAME
Scriptalicious - Delicious scripting goodies
SYNOPSIS
use Scriptalicious
-progname => "pu",
-version => $VERSION;
my $url = ".";
getopt("u|url" => \$url);
run("echo", "doing something with $url");
my $output = capture("svn", "info", $url);
__END__
=head1 NAME
pu - an uncarved block of wood
=head1 SYNOPSIS
pu [options] arguments
=head1 DESCRIPTION
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
=over
=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
warnings.
=item B<-d, --debug>
Display output to help someone debug this script, not the
process going on.
=back
DESCRIPTION
This module helps you write scripts, quickly. Just include the above as a template. 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.
To avoid all that unnecessary explicit importing of symbols, the following symbols and functions are exported into the caller's namespace:
- getopt(@getopt_args)
-
This just calls Getopt::Long::GetOptions (see Getopt::Long for details). It automatically adds to the arguments you give it some "standard" command line options.
$VERBOSE
-
Set to 0 by default, and 1 if
-v
or--verbose
was found during the call togetopt()
. Extra-v
's or--debug
will push this variable higher. If-q
or <--quiet> is specified, this will be less than one. $PROGNAME
-
It is recommended that you only ever read this variable, and pass it in via the import. This is not automatically extracted from the POD for performance reasons.
- getopt(@getopt_args)
-
Fetch arguments via
Getopt::Long::GetOptions
. Thebundling
option is enabled by default - which differs from the standard configuration of Getopt::Long. To alter the configuration, simply callGetopt::Long::config
. See Getopt::Long for more information. - say "something"
-
Prints a message to standard output, unless quiet mode (
-q
or--quiet
) was specified. For normal program messages. - mutter "progress"
-
Prints a message to standard output, if verbose mode (
-v
) or debug mode (-d
) is enabled (ie, if$VERBOSE > 0
). For messages designed to help a user of the script to see more information about what is going on. - whisper "detail"
-
Prints a message to standard output, if debug mode (
-d
) is enabled or multiple verbose options were passed (ie, if$VERBOSE > 1
). For messages designed to help a person debugging the script to see more information about what is going on internally to the script. - abort "won't go to sea in a storm"
-
Prints a short program usage message (extracted from the POD synopsis) and exits with an error code.
- moan "weather is miserable"
-
Prints a warning to standard error. It is preceded with the text
warning:
. The program does not exit. - barf "hit an iceberg"
-
Prints a warning to standard error. It is preceded with the text
warning:
. The program does not exit. - run("command", "arg1", "arg2")
-
Runs a command or closure, barf's with a relevant error message if there is a problem. Program output is suppressed unless running in verbose mode.
- run_err("command", "arg2", "arg1")
-
Same as run, but returns the error code rather than assuming that the command will successfully complete. Again, output it suppressed.
- capture("command", "1gra", "2gra")
-
runs a command, capturing its output, barfs if there is a problem. Returns the output of the command as a list.
- capture_err("command", "foo")
-
Works as capture, but the first returned item is the error code of the command ($?) rather than the first line of its output.
Usage:
my ($rc, @output) = capture_err("somecommand", @args);
AUTHOR
Sam Vilain, samv@marketview.co.nz