AppConfig::Std3pm
Subclass of appconfig that provides standard options
Usage
use AppConfig::Std;$config = AppConfig::Std->new();# all AppConfig methods supported$config->define('foo'); # define variable foo$config->set('foo', 25); # setting a variable$val = $config->get('foo'); # getting variable$val = $config->foo(); # shorthand for getting$config->args(\@ARGV); # parse command-line$config->file(".myconfigrc") # read config file
Overview
AppConfig::Std is a Perl module that provides a set of standard configuration variables and command-line switches. It is implemented as a subclass of AppConfig; AppConfig provides a general mechanism for handling global configuration variables.
The features provided by AppConfig::Std are:
- •
-
Standard command-line arguments: -help, -doc, -version, -verbose, and -debug. AppConfig::Std handles the -help, -doc, and -version switches for you, so you don't need to duplicate that code in all of your scripts. These are described below.
- •
-
The ARGCOUNT default is set to 1. This means that by default all switches are expected to take a value. To change this, set the ARGCOUNT parameter when defining the variable:
$config->define('verbose', { ARGCOUNT => 0 } );
Please read the copious documentation for AppConfig to find out what else you can do with this module.
Options
The module adds five standard configuration variables and command-line switches. You can define additional variables as you would with AppConfig.
Help
The -help switch will result in a short help message. This is generated using Pod::Usage, which displays the OPTIONS section of your pod. The script will exit with an exit value of 0.
Doc
The -doc switch will result in the entire documentation being formatted to the screen. This is also done with Pod::Usage. The script will exit with an exit value of 0.
Version
The -version switch will display the version of the invoking script. This assumes that you have defined $VERSION in your script with something like the following:
use vars qw( $VERSION );$VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
The script will exit with an exit value of 0.
Debug
The -debug switch just sets the debug variable. This is useful for displaying information in debug mode:
$foobar->dump() if $config->debug;
Verbose
The -verbose switch just sets the verbose variable. This is useful for displaying verbose information as a script runs:
print STDERR "Running foobar\n" if $config->verbose;
Todo
Please let me know if you have ideas for additional switches, or other modifications. Things currently being mulled:
- •
-
Support brief switches, such as
-has well as-help. This could be a config option for the constructor.
- •
-
Include a sample script called
mkscript, which would create a template script along with Makefile.PL, MANIFEST, etc. Kinda of a h2xs for scripts.
Examples
The following is the outline of a simple script that illustrates use of the AppConfig::Std module:
#!/usr/bin/perl -wuse strict;use AppConfig::Std;use vars qw( $VERSION );$VERSION = '1.0';my $config = AppConfig::Std->new();# parse command-line and handle std switches$config->args(\@ARGV);exit 0;__END__=head1 NAMEstandard pod format documentation
The pod documentation is expected to have the NAME, SYNOPSIS, DESCRIPTION, and OPTIONS sections. See the documentation for "pod2man" for more details.
Repository
<https://github.com/neilb/AppConfig-Std>
Releases
5 releases since Debian 9 (Stretch); the text changed 1 time.