AppConfig::Std(3pm)

πŸ“¦
version 1.10 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 -version for 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 the ARGCOUNT parameter 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 -h as 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.

🌈 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::Std requires version 1.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 -doc and -help switches. 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 the NOTES section in the documentation which describes the sections you should include in your documentation. AppConfig::Std uses Pod::Usage, which assumes well-formed pod.

🫢 REPOSITORY 🫢

https://github.com/neilb/AppConfig-Std


πŸŽ€ AUTHOR πŸŽ€

Neil Bowers <neil@bowers.com>


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