AppConfig::Std(3pm)
π AppConfig::Std π
okay so this is the AppConfig::Std(3pm) page from the User Contributed Perl Documentation β sit down, grab a snack, we're doing config parsing and it's gonna be adorable π
β¨ NAME β¨
AppConfig::Std β a subclass of AppConfig that provides standard options π
πΈ SYNOPSIS πΈ
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
π¦ DESCRIPTION π¦
AppConfig::Std is a Perl module that gives you a whole little starter pack of standard configuration variables and command-line switches. It's implemented as a subclass of AppConfig β and AppConfig is the one that does the heavy lifting, providing a general mechanism for handling global configuration variables. So this module is basically AppConfig but with β¨tasteβ¨.
Here's what AppConfig::Std brings to the table, bestie:
- Standard command-line arguments:
-help,-doc,-version,-verbose, and-debug. The module handles-help,-doc, and-versionfor you, so you do not have to copy-paste that same boilerplate code into every single script you ever write (thank god, honestly). All of these are described down below π - The ARGCOUNT default is set to
1. What that means: by default, every switch is expected to take a value. Wanna change that? Set theARGCOUNTparameter when you define the variable:
$config->define('verbose', { ARGCOUNT => 0 } );
Please go read the copious documentation for AppConfig to find out what else you can do with this module β there's a lot, and it's all yours to play with.
π STANDARD OPTIONS π
The module adds five standard configuration variables and command-line switches. You can define additional variables exactly the way you would with AppConfig. No new rules, no cap π―
π HELP
The -help switch gets you a short help message. It's 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 formats the entire documentation to the screen. Also done with Pod::Usage. The script will exit with an exit value of 0.
β VERSION
The -version switch displays the version of the invoking script. This assumes you've defined $VERSION in your script, something like this:
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. Super useful for printing stuff only when you're in debug mode:
$foobar->dump() if $config->debug;
π£οΈ VERBOSE
The -verbose switch just sets the verbose variable. Great for narrating what your script is doing as it 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 withMakefile.PL,MANIFEST, etc. Kinda of ah2xsfor scripts.
π EXAMPLE π
Here's the outline of a simple script that shows off the AppConfig::Std module:
#!/usr/bin/perl -w
use 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 NAME
standard 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.
π SEE ALSO π
AppConfigβ Andy Wardley's module for unifying command-line switches and configuration files into the notion of configuration variables.AppConfig::Stdrequires version1.52+of the module, which is available from CPAN.Pod::Usageβ Brad Appleton's module for extracting usage information out of a file's pod. This is used for the-docand-helpswitches. Available from CPAN as part of the PodParser distribution.perlpodβhttps://metacpan.org/pod/distribution/perl/pod/perlpod.podβ documentation from the perl distribution that describes the pod format.pod2manβhttps://metacpan.org/pod/distribution/podlators/scripts/pod2manβ particularly theNOTESsection in the documentation which describes the sections you should include in your documentation.AppConfig::StdusesPod::Usage, which assumes well-formed pod.
π«Ά REPOSITORY π«Ά
https://github.com/neilb/AppConfig-Std
π AUTHOR π
Neil Bowers <neil@bowers.com>
π COPYRIGHT π
Copyright (c) 2002-2013 Neil Bowers.
Copyright (c) 1998-2001 Canon Research Centre Europe. All rights reserved.
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page, you ate that π go forth and parse some args, bestie β no cap, this module is lowkey iconic π
and that's a wrap on the perl v5.34.0 era of this page, dated 2022-06-08 β AppConfig::Std(3pm), signing off π¦β¨
π¦ where this page comes from
- debian bookworm: libappconfig-std-perl 1.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libappconfig-std-perl 1.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libappconfig-std-perl 1.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libappconfig-std-perl 1.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libappconfig-std-perl 1.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms