1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
4 .\" ========================================================================
5 .de Sh \" Subsection heading
13 .de Sp \" Vertical space (when we can't use .PP)
17 .de Vb \" Begin verbatim text
22 .de Ve \" End verbatim text
26 .\" Set up some character translations and predefined strings. \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote. | will give a
29 .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
37 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD. Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
57 . tm Index:\\$1\t\\n%\t"\\$2"
63 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear. Run. Save yourself. No user-serviceable parts.
70 . \" fudge factors for nroff and troff
79 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 . \" simple accents for nroff and troff
95 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
102 . \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 . \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 . \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
129 .\" ========================================================================
131 .IX Title "AppConfig 3"
132 .TH AppConfig 3 "2007-07-06" "perl v5.8.7" "User Contributed Perl Documentation"
134 AppConfig \- Perl5 module for reading configuration files and parsing command line arguments.
136 .IX Header "SYNOPSIS"
142 \& # create a new AppConfig object
143 \& my $config = AppConfig\->new( \e%cfg );
147 \& # define a new variable
148 \& $config\->define( $varname => \e%varopts );
152 \& # create/define combined
153 \& my $config = AppConfig\->new( \e%cfg,
154 \& $varname => \e%varopts,
155 \& $varname => \e%varopts,
161 \& # set/get the value
162 \& $config\->set( $varname, $value );
163 \& $config\->get($varname);
168 \& $config\->varname($value);
169 \& $config\->varname;
173 \& # read configuration file
174 \& $config\->file($file);
178 \& # parse command line options
179 \& $config\->args(\e@args); # default to \e@ARGV
183 \& # advanced command line options with Getopt::Long
184 \& $config\->getopt(\e@args); # default to \e@ARGV
188 \& # parse CGI parameters (GET method)
189 \& $config\->cgi($query); # default to $ENV{ QUERY_STRING }
192 .IX Header "OVERVIEW"
193 AppConfig is a Perl5 module for managing application configuration
194 information. It maintains the state of any number of variables and
195 provides methods for parsing configuration files, command line
196 arguments and \s-1CGI\s0 script parameters.
198 Variables values may be set via configuration files. Variables may be
199 flags (On/Off), take a single value, or take multiple values stored as a
200 list or hash. The number of arguments a variable expects is determined
201 by its configuration when defined.
216 \& # multiple list value
222 \& # multiple hash value
223 \& book camel = Programming Perl
224 \& book llama = Learning Perl
227 The '\-' prefix can be used to reset a variable to its default value and
228 the '+' prefix can be used to set it to 1
235 Variable, environment variable and tilde (home directory) expansions
236 can be applied (selectively, if necessary) to the values read from
240 \& home = ~ # home directory
241 \& nntp = ${NNTPSERVER} # environment variable
242 \& html = $home/html # internal variables
243 \& img = $html/images
246 Configuration files may be arranged in blocks as per the style of Win32
247 \&\*(L"\s-1INI\s0\*(R" files.
252 \& src = ~/websrc/docs/$site
253 \& lib = ~/websrc/lib
254 \& dest = ~/public_html/$site
259 \& header = $lib/header
260 \& footer = $lib/footer
263 You can also use Perl's \*(L"heredoc\*(R" syntax to define a large block of
264 text in a configuration file.
267 \& multiline = <<FOOBAR
274 \& paths exe = "${PATH}:${HOME}/.bin"
275 \& paths link = <<'FOO'
276 \& ${LD_LIBARRAY_PATH}:${HOME}/lib
280 Variables may also be set by parsing command line arguments.
283 \& myapp \-verbose \-site kfs \-file f1 \-file f2
286 AppConfig provides a simple method (\fIargs()\fR) for parsing command line
287 arguments. A second method (\fIgetopt()\fR) allows more complex argument
288 processing by delegation to Johan Vroman's Getopt::Long module.
290 AppConfig also allows variables to be set by parameters passed to a
291 \&\s-1CGI\s0 script via the \s-1URL\s0 (\s-1GET\s0 method).
294 \& http://www.nowhere.com/cgi\-bin/myapp?verbose&site=kfs
297 .IX Header "PREREQUISITES"
298 AppConfig requires Perl 5.005 or later.
300 The Getopt::Long and Test::More modules should be installed.
301 If you are using a recent version of Perl (e.g. 5.8.0) then these
302 should already be installed.
303 .SH "OBTAINING AND INSTALLING THE AppConfig MODULE BUNDLE"
304 .IX Header "OBTAINING AND INSTALLING THE AppConfig MODULE BUNDLE"
305 The AppConfig module bundle is available from \s-1CPAN\s0. As the 'perlmod'
306 manual page explains:
309 \& CPAN stands for the Comprehensive Perl Archive Network.
310 \& This is a globally replicated collection of all known Perl
311 \& materials, including hundreds of unbundled modules.
319 \& For an up\-to\-date listing of CPAN sites, see
320 \& http://www.perl.com/perl/ or ftp://ftp.perl.com/perl/ .
323 Within the \s-1CPAN\s0 archive, AppConfig is in the category:
326 \& 12) Option, Argument, Parameter and Configuration File Processing
329 The module is available in the following directories:
332 \& /modules/by\-module/AppConfig/AppConfig\-<version>.tar.gz
333 \& /authors/id/ABW/AppConfig\-<version>.tar.gz
336 AppConfig is distributed as a single gzipped tar archive file:
339 \& AppConfig\-<version>.tar.gz
342 Note that \*(L"<version>\*(R" represents the current AppConfig version
343 number, of the form \*(L"n.nn\*(R", e.g. \*(L"3.14\*(R". See the \s-1REVISION\s0 section
344 below to determine the current version number for AppConfig.
346 Unpack the archive to create a AppConfig installation directory:
349 \& gunzip AppConfig\-<version>.tar.gz
350 \& tar xvf AppConfig\-<version>.tar
353 \&'cd' into that directory, make, test and install the modules:
356 \& cd AppConfig\-<version>
363 The 't' sub-directory contains a number of test scripts that are run when
364 a 'make test' is run.
366 The 'make install' will install the module on your system. You may need
367 administrator privileges to perform this task. If you install the module
368 in a local directory (for example, by executing \*(L"perl Makefile.PL
369 LIB=~/lib\*(R" in the above \- see \f(CW\*(C`perldoc MakeMaker\*(C'\fR for full details), you
370 will need to ensure that the \s-1PERL5LIB\s0 environment variable is set to
371 include the location, or add a line to your scripts explicitly naming the
375 \& use lib '/local/path/to/lib';
378 The 'examples' sub-directory contains some simple examples of using the
381 .IX Header "DESCRIPTION"
382 .Sh "\s-1USING\s0 \s-1THE\s0 AppConfig \s-1MODULE\s0"
383 .IX Subsection "USING THE AppConfig MODULE"
384 To import and use the AppConfig module the following line should
385 appear in your Perl script:
391 To import constants defined by the AppConfig module, specify the name of
392 one or more of the constant or tag sets as parameters to \f(CW\*(C`use\*(C'\fR:
395 \& use AppConfig qw(:expand :argcount);
398 See \*(L"\s-1CONSTANT\s0 \s-1DEFINITIONS\s0\*(R" below for more information on the constant
399 tagsets defined by AppConfig.
401 AppConfig is implemented using object-oriented methods. A
402 new AppConfig object is created and initialised using the
403 \&\fInew()\fR method. This returns a reference to a new AppConfig
407 \& my $config = AppConfig\->new();
410 This will create and return a reference to a new AppConfig object.
412 In doing so, the AppConfig object also creates an internal reference
413 to an AppConfig::State object in which to store variable state. All
414 arguments passed into the AppConfig constructor are passed directly
415 to the AppConfig::State constructor.
417 The first (optional) parameter may be a reference to a hash array
418 containing configuration information.
421 \& my $config = AppConfig\->new( {
423 \& ERROR => \e&my_error,
425 \& DEFAULT => "<unset>",
426 \& ARGCOUNT => ARGCOUNT_ONE,
431 See AppConfig::State for full details of the configuration options
432 available. These are, in brief:
435 Used to set case sensitivity for variable names (default: off).
436 .IP "\s-1CREATE\s0" 4
438 Used to indicate that undefined variables should be created automatically
440 .IP "\s-1GLOBAL\s0" 4
442 Reference to a hash array of global values used by default when defining
443 variables. Valid global values are \s-1DEFAULT\s0, \s-1ARGCOUNT\s0, \s-1EXPAND\s0, \s-1VALIDATE\s0
445 .IP "\s-1PEDANTIC\s0" 4
447 Used to indicate that command line and configuration file parsing routines
448 should return immediately on encountering an error.
451 Used to provide a error handling routine. Arguments as per \fIprintf()\fR.
453 Subsequent parameters may be variable definitions. These are passed
454 to the \fIdefine()\fR method, described below in \*(L"\s-1DEFINING\s0 \s-1VARIABLES\s0\*(R".
457 \& my $config = AppConfig\->new("foo", "bar", "baz");
458 \& my $config = AppConfig\->new( { CASE => 1 }, qw(foo bar baz) );
461 Note that any unresolved method calls to AppConfig are automatically
462 delegated to the AppConfig::State object. In practice, it means that
463 it is possible to treat the AppConfig object as if it were an
464 AppConfig::State object:
467 \& # create AppConfig
468 \& my $config = AppConfig\->new('foo', 'bar');
472 \& # methods get passed through to internal AppConfig::State
473 \& $config\->foo(100);
474 \& $config\->set('bar', 200);
475 \& $config\->define('baz');
476 \& $config\->baz(300);
478 .Sh "\s-1DEFINING\s0 \s-1VARIABLES\s0"
479 .IX Subsection "DEFINING VARIABLES"
480 The \f(CW\*(C`define()\*(C'\fR method (delegated to AppConfig::State) is used to
481 pre-declare a variable and specify its configuration.
484 \& $config\->define("foo");
487 Variables may also be defined directly from the AppConfig \fInew()\fR
491 \& my $config = AppConfig\->new("foo");
494 In both simple examples above, a new variable called \*(L"foo\*(R" is defined. A
495 reference to a hash array may also be passed to specify configuration
496 information for the variable:
499 \& $config\->define("foo", {
501 \& ALIAS => 'metavar1',
505 Configuration items specified in the \s-1GLOBAL\s0 option to the module
506 constructor are applied by default when variables are created. e.g.
509 \& my $config = AppConfig\->new( {
511 \& DEFAULT => "<undef>",
512 \& ARGCOUNT => ARGCOUNT_ONE,
518 \& $config\->define("foo");
519 \& $config\->define("bar", { ARGCOUNT => ARGCOUNT_NONE } );
525 \& my $config = AppConfig\->new();
529 \& $config\->define( "foo", {
530 \& DEFAULT => "<undef>",
531 \& ARGCOUNT => ARGCOUNT_ONE,
536 \& $config\->define( "bar",
537 \& DEFAULT => "<undef>",
538 \& ARGCOUNT => ARGCOUNT_NONE,
542 Multiple variables may be defined in the same call to \fIdefine()\fR.
543 Configuration hashes for variables can be omitted.
546 \& $config\->define("foo", "bar" => { ALIAS = "boozer" }, "baz");
549 See AppConfig::State for full details of the configuration options
550 available when defining variables. These are, in brief:
551 .IP "\s-1DEFAULT\s0" 4
553 The default value for the variable (default: undef).
556 One or more (list reference or \*(L"list|like|this\*(R") alternative names for the
558 .IP "\s-1ARGCOUNT\s0" 4
560 Specifies the number and type of arguments that the variable expects.
561 Constants in \f(CW\*(C`:expand\*(C'\fR tag set define \s-1ARGCOUNT_NONE\s0 \- simple on/off flag
562 (default), \s-1ARGCOUNT_ONE\s0 \- single value, \s-1ARGCOUNT_LIST\s0 \- multiple values
563 accessed via list reference, \s-1ARGCOUNT_HASH\s0 \- hash table, \*(L"key=value\*(R",
564 accessed via hash reference.
567 Used to provide an argument specification string to pass to Getopt::Long
568 via AppConfig::Getopt. E.g. \*(L"=i\*(R", \*(L":s\*(R", \*(L"=s@\*(R". This can also be used to
569 implicitly set the \s-1ARGCOUNT\s0 value (\f(CW\*(C`/^!/\*(C'\fR = \s-1ARGCOUNT_NONE\s0, \f(CW\*(C`/@/\*(C'\fR =
570 \&\s-1ARGCOUNT_LIST\s0, \f(CW\*(C`/%/\*(C'\fR = \s-1ARGCOUNT_HASH\s0, \f(CW\*(C`/[=:].*/\*(C'\fR = \s-1ARGCOUNT_ONE\s0)
571 .IP "\s-1EXPAND\s0" 4
573 Specifies which variable expansion policies should be used when parsing
574 configuration files. Constants in \f(CW\*(C`:expand\*(C'\fR tag set define:
577 \& EXPAND_NONE \- no expansion (default)
578 \& EXPAND_VAR \- expand C<$var> or C<$(var)> as other variables
579 \& EXPAND_UID \- expand C<~> and C<~uid> as user's home directory
580 \& EXPAND_ENV \- expand C<${var}> as environment variable
581 \& EXPAND_ALL \- do all expansions.
583 .IP "\s-1VALIDATE\s0" 4
585 Regex which the intended variable value should match or code reference
586 which returns 1 to indicate successful validaton (variable may now be set).
587 .IP "\s-1ACTION\s0" 4
589 Code reference to be called whenever variable value changes.
590 .Sh "\s-1COMPACT\s0 \s-1FORMAT\s0 \s-1DEFINITION\s0"
591 .IX Subsection "COMPACT FORMAT DEFINITION"
592 Variables can be specified using a compact format. This is identical to
593 the specification format of Getopt::Long and is of the form:
596 \& "name|alias|alias<argopts>"
599 The first element indicates the variable name and subsequent \s-1ALIAS\s0
600 values may be added, each separated by a vertical bar '|'.
602 The <argopts> element indicates the \s-1ARGCOUNT\s0 value and may be one of
612 Additional constructs supported by Getopt::Long may be specified instead
613 of the \*(L"=s\*(R" element (e.g. \*(L"=f\*(R"). The entire <argopts> element
614 is stored in the \s-1ARGS\s0 parameter for the variable and is passed intact to
615 Getopt::Long when the \fIgetopt()\fR method is called.
617 The following examples demonstrate use of the comapct format, with their
618 equivalent full specifications:
621 \& $config\->define("foo|bar|baz!");
627 \& ALIAS => "bar|baz",
628 \& ARGCOUNT => ARGCOUNT_NONE,
633 \& $config\->define("name=s");
639 \& ARGCOUNT => ARGCOUNT_ONE,
644 \& $config\->define("file|filelist|f=s@");
650 \& ALIAS => "filelist|f",
651 \& ARGCOUNT => ARGCOUNT_LIST,
656 \& $config\->define("user|u=s%");
663 \& ARGCOUNT => ARGCOUNT_HASH,
667 Additional configuration options may be specified by hash reference, as per
668 normal. The compact definition format will override any configuration
669 values provided for \s-1ARGS\s0 and \s-1ARGCOUNT\s0.
672 \& $config\->define("file|filelist|f=s@", { VALIDATE = \e&check_file() } );
674 .Sh "\s-1READING\s0 \s-1AND\s0 \s-1MODIFYING\s0 \s-1VARIABLE\s0 \s-1VALUES\s0"
675 .IX Subsection "READING AND MODIFYING VARIABLE VALUES"
676 AppConfig defines two methods (via AppConfig::State) to manipulate variable
680 \& set($variable, $value);
684 Once defined, variables may be accessed directly as object methods where
685 the method name is the same as the variable name. i.e.
688 \& $config\->set("verbose", 1);
694 \& $config\->verbose(1);
697 Note that AppConfig defines the following methods:
706 And also, through delegation to AppConfig::State:
715 If you define a variable with one of the above names, you will not be able
716 to access it directly as an object method. i.e.
722 This will call the \fIfile()\fR method, instead of returning the value of the
723 \&'file' variable. You can work around this by explicitly calling \fIget()\fR and
724 \&\fIset()\fR on a variable whose name conflicts:
727 \& $config\->get('file');
730 or by defining a \*(L"safe\*(R" alias by which the variable can be accessed:
733 \& $config\->define("file", { ALIAS => "fileopt" });
735 \& $config\->define("file|fileopt");
740 \& $config\->fileopt();
743 Without parameters, the current value of the variable is returned. If
744 a parameter is specified, the variable is set to that value and the
745 result of the \fIset()\fR operation is returned.
748 \& $config\->age(29); # sets 'age' to 29, returns 1 (ok)
749 \& print $config\->age(); # prints "29"
752 The \fIvarlist()\fR method can be used to extract a number of variables into
753 a hash array. The first parameter should be a regular expression
754 used for matching against the variable names.
757 \& my %vars = $config\->varlist("^file"); # all "file*" variables
760 A second parameter may be specified (any true value) to indicate that
761 the part of the variable name matching the regex should be removed
762 when copied to the target hash.
765 \& $config\->file_name("/tmp/file");
766 \& $config\->file_path("/foo:/bar:/baz");
770 \& my %vars = $config\->varlist("^file_", 1);
775 \& # name => /tmp/file
776 \& # path => "/foo:/bar:/baz"
778 .Sh "\s-1READING\s0 \s-1CONFIGURATION\s0 \s-1FILES\s0"
779 .IX Subsection "READING CONFIGURATION FILES"
780 The AppConfig module provides a streamlined interface for reading
781 configuration files with the AppConfig::File module. The \fIfile()\fR method
782 automatically loads the AppConfig::File module and creates an object
783 to process the configuration file or files. Variables stored in the
784 internal AppConfig::State are automatically updated with values specified
785 in the configuration file.
788 \& $config\->file($filename);
791 Multiple files may be passed to \fIfile()\fR and should indicate the file name
792 or be a reference to an open file handle or glob.
795 \& $config\->file($filename, $filehandle, \e*STDIN, ...);
798 The file may contain blank lines and comments (prefixed by '#') which
799 are ignored. Continutation lines may be marked by ending the line with
803 \& # this is a comment
804 \& callsign = alpha bravo camel delta echo foxtrot golf hipowls \e
805 \& india juliet kilo llama mike november oscar papa \e
806 \& quebec romeo sierra tango umbrella victor whiskey \e
807 \& x\-ray yankee zebra
810 Variables that are simple flags and do not expect an argument (\s-1ARGCOUNT\s0 =
811 \&\s-1ARGCOUNT_NONE\s0) can be specified without any value. They will be set with
812 the value 1, with any value explicitly specified (except \*(L"0\*(R" and \*(L"off\*(R")
813 being ignored. The variable may also be specified with a \*(L"no\*(R" prefix to
814 implicitly set the variable to 0.
818 \& verbose = 1 # on (1)
819 \& verbose = 0 # off (0)
820 \& verbose off # off (0)
821 \& verbose on # on (1)
822 \& verbose mumble # on (1)
823 \& noverbose # off (0)
826 Variables that expect an argument (\s-1ARGCOUNT\s0 = \s-1ARGCOUNT_ONE\s0) will be set to
827 whatever follows the variable name, up to the end of the current line
828 (including any continuation lines). An optional equals sign may be inserted
829 between the variable and value for clarity.
832 \& room = /home/kitchen
833 \& room /home/bedroom
836 Each subsequent re-definition of the variable value overwrites the previous
840 \& print $config\->room(); # prints "/home/bedroom"
843 Variables may be defined to accept multiple values (\s-1ARGCOUNT\s0 = \s-1ARGCOUNT_LIST\s0).
844 Each subsequent definition of the variable adds the value to the list of
845 previously set values for the variable.
852 A reference to a list of values is returned when the variable is requested.
855 \& my $beverages = $config\->drinks();
856 \& print join(", ", @$beverages); # prints "coffee, tea"
859 Variables may also be defined as hash lists (\s-1ARGCOUNT\s0 = \s-1ARGCOUNT_HASH\s0).
860 Each subsequent definition creates a new key and value in the hash array.
867 A reference to the hash is returned when the variable is requested.
870 \& my $aliases = $config\->alias();
871 \& foreach my $k (keys %$aliases) {
872 \& print "$k => $aliases\->{ $k }\en";
876 The '\-' prefix can be used to reset a variable to its default value and
877 the '+' prefix can be used to set it to 1
883 .Sh "\s-1VARIABLE\s0 \s-1EXPANSION\s0"
884 .IX Subsection "VARIABLE EXPANSION"
885 Variable values may contain references to other AppConfig variables,
886 environment variables and/or users' home directories. These will be
887 expanded depending on the \s-1EXPAND\s0 value for each variable or the \s-1GLOBAL\s0
888 \&\s-1EXPAND\s0 value.
890 Three different expansion types may be applied:
893 \& bin = ~/bin # expand '~' to home dir if EXPAND_UID
894 \& tmp = ~abw/tmp # as above, but home dir for user 'abw'
898 \& perl = $bin/perl # expand value of 'bin' variable if EXPAND_VAR
899 \& ripl = $(bin)/ripl # as above with explicit parens
903 \& home = ${HOME} # expand HOME environment var if EXPAND_ENV
906 See AppConfig::State for more information on expanding variable values.
908 The configuration files may have variables arranged in blocks. A block
909 header, consisting of the block name in square brackets, introduces a
910 configuration block. The block name and an underscore are then prefixed
911 to the names of all variables subsequently referenced in that block. The
912 block continues until the next block definition or to the end of the current
917 \& foo = 10 # block1_foo = 10
922 \& foo = 20 # block2_foo = 20
924 .Sh "\s-1PARSING\s0 \s-1COMMAND\s0 \s-1LINE\s0 \s-1OPTIONS\s0"
925 .IX Subsection "PARSING COMMAND LINE OPTIONS"
926 There are two methods for processing command line options. The first,
927 \&\fIargs()\fR, is a small and efficient implementation which offers basic
928 functionality. The second, \fIgetopt()\fR, offers a more powerful and complete
929 facility by delegating the task to Johan Vroman's Getopt::Long module.
930 The trade-off between \fIargs()\fR and \fIgetopt()\fR is essentially one of speed/size
931 against flexibility. Use as appropriate. Both implement on-demand loading
932 of modules and incur no overhead until used.
934 The \fIargs()\fR method is used to parse simple command line options. It
935 automatically loads the AppConfig::Args module and creates an object
936 to process the command line arguments. Variables stored in the internal
937 AppConfig::State are automatically updated with values specified in the
940 The method should be passed a reference to a list of arguments to parse.
941 The \f(CW@ARGV\fR array is used if \fIargs()\fR is called without parameters.
944 \& $config\->args(\e@myargs);
945 \& $config\->args(); # uses @ARGV
948 Arguments are read and shifted from the array until the first is
949 encountered that is not prefixed by '\-' or '\-\-'. At that point, the
950 method returns 1 to indicate success, leaving any unprocessed arguments
951 remaining in the list.
953 Each argument should be the name or alias of a variable prefixed by
954 \&'\-' or '\-\-'. Arguments that are not prefixed as such (and are not an
955 additional parameter to a previous argument) will cause a warning to be
956 raised. If the \s-1PEDANTIC\s0 option is set, the method will return 0
957 immediately. With \s-1PEDANTIC\s0 unset (default), the method will continue
958 to parse the rest of the arguments, returning 0 when done.
960 If the variable is a simple flag (\s-1ARGCOUNT\s0 = \s-1ARGCOUNT_NONE\s0)
961 then it is set to the value 1. The variable may be prefixed by \*(L"no\*(R" to
965 \& myprog \-verbose \-\-debug \-notaste # $config\->verbose(1)
966 \& # $config\->debug(1)
967 \& # $config\->taste(0)
970 Variables that expect an additional argument (\s-1ARGCOUNT\s0 != 0) will be set to
971 the value of the argument following it.
974 \& myprog \-f /tmp/myfile # $config\->file('/tmp/file');
977 Variables that expect multiple values (\s-1ARGCOUNT\s0 = \s-1ARGCOUNT_LIST\s0 or
978 \&\s-1ARGCOUNT_HASH\s0) will have sucessive values added each time the option
982 \& myprog \-file /tmp/foo \-file /tmp/bar # $config\->file('/tmp/foo')
983 \& # $config\->file('/tmp/bar')
987 \& # file => [ '/tmp/foo', '/tmp/bar' ]
991 \& myprog \-door "jim=Jim Morrison" \-door "ray=Ray Manzarek"
992 \& # $config\->door("jim=Jim Morrison");
993 \& # $config\->door("ray=Ray Manzarek");
997 \& # door => { 'jim' => 'Jim Morrison', 'ray' => 'Ray Manzarek' }
1000 See AppConfig::Args for further details on parsing command line
1003 The \fIgetopt()\fR method provides a way to use the power and flexibility of
1004 the Getopt::Long module to parse command line arguments and have the
1005 internal values of the AppConfig object updates automatically.
1007 The first (non\-list reference) parameters may contain a number of
1008 configuration string to pass to Getopt::Long::Configure. A reference
1009 to a list of arguments may additionally be passed or \f(CW@ARGV\fR is used by
1013 \& $config\->getopt(); # uses @ARGV
1014 \& $config\->getopt(\e@myargs);
1015 \& $config\->getopt(qw(auto_abbrev debug)); # uses @ARGV
1016 \& $config\->getopt(qw(debug), \e@myargs);
1019 See Getopt::Long for details of the configuration options available.
1021 The \fIgetopt()\fR method constructs a specification string for each internal
1022 variable and then initialises Getopt::Long with these values. The
1023 specification string is constructed from the name, any aliases (delimited
1024 by a vertical bar '|') and the value of the \s-1ARGS\s0 parameter.
1027 \& $config\->define("foo", {
1029 \& ALIAS => "bar|baz",
1034 \& # Getopt::Long specification: "foo|bar|baz=i"
1037 Errors and warning generated by the Getopt::Long module are trapped and
1038 handled by the AppConfig error handler. This may be a user-defined
1039 routine installed with the \s-1ERROR\s0 configuration option.
1041 Please note that the AppConfig::Getopt interface is still experimental
1042 and may not be 100% operational. This is almost undoubtedly due to
1043 problems in AppConfig::Getopt rather than Getopt::Long.
1044 .Sh "\s-1PARSING\s0 \s-1CGI\s0 \s-1PARAMETERS\s0"
1045 .IX Subsection "PARSING CGI PARAMETERS"
1046 The \fIcgi()\fR method provides an interface to the AppConfig::CGI module
1047 for updating variable values based on the parameters appended to the
1048 \&\s-1URL\s0 for a \s-1CGI\s0 script. This is commonly known as the \s-1CGI\s0
1049 \&\*(L"\s-1GET\s0\*(R" method. The \s-1CGI\s0 \*(L"\s-1POST\s0\*(R" method is currently not supported.
1051 Parameter definitions are separated from the \s-1CGI\s0 script name by a
1052 question mark and from each other by ampersands. Where variables
1053 have specific values, these are appended to the variable with an
1057 \& http://www.here.com/cgi\-bin/myscript?foo=bar&baz=qux&verbose
1061 \& # $config\->foo('bar');
1062 \& # $config\->baz('qux');
1063 \& # $config\->verbose(1);
1066 Certain values specified in a \s-1URL\s0 must be escaped in the appropriate
1067 manner (see \s-1CGI\s0 specifications at http://www.w3c.org/ for full details).
1068 The AppConfig::CGI module automatically unescapes the \s-1CGI\s0 query string
1069 to restore the parameters to their intended values.
1072 \& http://where.com/mycgi?title=%22The+Wrong+Trousers%22
1076 \& # $config\->title('"The Wrong Trousers"');
1079 Please be considerate of the security implications of providing writeable
1080 access to script variables via \s-1CGI\s0.
1083 \& http://rebel.alliance.com/cgi\-bin/...
1084 \& .../send_report?file=%2Fetc%2Fpasswd&email=darth%40empire.com
1087 To avoid any accidental or malicious changing of \*(L"private\*(R" variables,
1088 define only the \*(L"public\*(R" variables before calling the \fIcgi()\fR (or any
1089 other) method. Further variables can subequently be defined which
1090 can not be influenced by the \s-1CGI\s0 parameters.
1093 \& $config\->define('verbose', 'debug')
1094 \& $config\->cgi(); # can only set verbose and debug
1098 \& $config\->define('email', 'file');
1099 \& $config\->file($cfgfile); # can set verbose, debug, email + file
1101 .SH "CONSTANT DEFINITIONS"
1102 .IX Header "CONSTANT DEFINITIONS"
1103 A number of constants are defined by the AppConfig module. These may be
1104 accessed directly (e.g. AppConfig::EXPAND_VARS) or by first importing them
1105 into the caller's package. Constants are imported by specifying their
1106 names as arguments to \f(CW\*(C`use AppConfig\*(C'\fR or by importing a set of constants
1107 identified by its \*(L"tag set\*(R" name.
1110 \& use AppConfig qw(ARGCOUNT_NONE ARGCOUNT_ONE);
1114 \& use AppConfig qw(:argcount);
1117 The following tag sets are defined:
1120 The ':expand' tagset defines the following constants:
1127 \& EXPAND_ALL # EXPAND_VAR | EXPAND_UID | EXPAND_ENV
1131 See AppConfig::File for full details of the use of these constants.
1133 .IX Item ":argcount"
1134 The ':argcount' tagset defines the following constants:
1143 See AppConfig::State for full details of the use of these constants.
1146 Andy Wardley, <abw@wardley.org>
1148 With contributions from Dave Viner, Ijon Tichy, Axel Gerstmair and
1149 many others whose names have been lost to the sands of time (reminders
1152 .IX Header "COPYRIGHT"
1153 Copyright (C) 1997\-2007 Andy Wardley. All Rights Reserved.
1155 Copyright (C) 1997,1998 Canon Research Centre Europe Ltd.
1157 This module is free software; you can redistribute it and/or modify it
1158 under the same terms as Perl itself.
1160 .IX Header "SEE ALSO"
1161 AppConfig::State, AppConfig::File, AppConfig::Args, AppConfig::Getopt,
1162 AppConfig::CGI, Getopt::Long