Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / AppConfig.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
12 ..
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
16 ..
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
21 ..
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
25 ..
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<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
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
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
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.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
58 ..
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
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
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
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'
101 .\}
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 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "AppConfig 3"
132 .TH AppConfig 3 "2007-07-06" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 AppConfig \- Perl5 module for reading configuration files and parsing command line arguments.
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 1
138 \&    use AppConfig;
139 .Ve
140 .PP
141 .Vb 2
142 \&    # create a new AppConfig object
143 \&    my $config = AppConfig\->new( \e%cfg );
144 .Ve
145 .PP
146 .Vb 2
147 \&    # define a new variable
148 \&    $config\->define( $varname => \e%varopts );
149 .Ve
150 .PP
151 .Vb 6
152 \&    # create/define combined
153 \&    my $config = AppConfig\->new( \e%cfg, 
154 \&        $varname => \e%varopts,
155 \&        $varname => \e%varopts,
156 \&        ...
157 \&    );
158 .Ve
159 .PP
160 .Vb 3
161 \&    # set/get the value
162 \&    $config\->set( $varname, $value );
163 \&    $config\->get($varname);
164 .Ve
165 .PP
166 .Vb 3
167 \&    # shortcut form
168 \&    $config\->varname($value);
169 \&    $config\->varname;
170 .Ve
171 .PP
172 .Vb 2
173 \&    # read configuration file
174 \&    $config\->file($file);
175 .Ve
176 .PP
177 .Vb 2
178 \&    # parse command line options
179 \&    $config\->args(\e@args);      # default to \e@ARGV
180 .Ve
181 .PP
182 .Vb 2
183 \&    # advanced command line options with Getopt::Long
184 \&    $config\->getopt(\e@args);    # default to \e@ARGV
185 .Ve
186 .PP
187 .Vb 2
188 \&    # parse CGI parameters (GET method)
189 \&    $config\->cgi($query);       # default to $ENV{ QUERY_STRING }
190 .Ve
191 .SH "OVERVIEW"
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.
197 .PP
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.
202 .PP
203 .Vb 4
204 \&    # flags
205 \&    verbose 
206 \&    nohelp
207 \&    debug = On
208 .Ve
209 .PP
210 .Vb 2
211 \&    # single value
212 \&    home  = /home/abw/
213 .Ve
214 .PP
215 .Vb 3
216 \&    # multiple list value
217 \&    file = /tmp/file1
218 \&    file = /tmp/file2
219 .Ve
220 .PP
221 .Vb 3
222 \&    # multiple hash value
223 \&    book  camel = Programming Perl
224 \&    book  llama = Learning Perl
225 .Ve
226 .PP
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
229 .PP
230 .Vb 2
231 \&    \-verbose
232 \&    +debug
233 .Ve
234 .PP
235 Variable, environment variable and tilde (home directory) expansions
236 can be applied (selectively, if necessary) to the values read from 
237 configuration files:
238 .PP
239 .Vb 4
240 \&    home = ~                    # home directory
241 \&    nntp = ${NNTPSERVER}        # environment variable
242 \&    html = $home/html           # internal variables
243 \&    img  = $html/images
244 .Ve
245 .PP
246 Configuration files may be arranged in blocks as per the style of Win32 
247 \&\*(L"\s-1INI\s0\*(R" files.
248 .PP
249 .Vb 5
250 \&    [file]
251 \&    site = kfs
252 \&    src  = ~/websrc/docs/$site
253 \&    lib  = ~/websrc/lib
254 \&    dest = ~/public_html/$site
255 .Ve
256 .PP
257 .Vb 3
258 \&    [page]
259 \&    header = $lib/header
260 \&    footer = $lib/footer
261 .Ve
262 .PP
263 You can also use Perl's \*(L"heredoc\*(R" syntax to define a large block of
264 text in a configuration file.
265 .PP
266 .Vb 4
267 \&    multiline = <<FOOBAR
268 \&    line 1
269 \&    line 2
270 \&    FOOBAR
271 .Ve
272 .PP
273 .Vb 4
274 \&    paths  exe  = "${PATH}:${HOME}/.bin"
275 \&    paths  link = <<'FOO'
276 \&    ${LD_LIBARRAY_PATH}:${HOME}/lib
277 \&    FOO
278 .Ve
279 .PP
280 Variables may also be set by parsing command line arguments.
281 .PP
282 .Vb 1
283 \&    myapp \-verbose \-site kfs \-file f1 \-file f2
284 .Ve
285 .PP
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.
289 .PP
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).
292 .PP
293 .Vb 1
294 \&    http://www.nowhere.com/cgi\-bin/myapp?verbose&site=kfs
295 .Ve
296 .SH "PREREQUISITES"
297 .IX Header "PREREQUISITES"
298 AppConfig requires Perl 5.005 or later.  
299 .PP
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:
307 .PP
308 .Vb 3
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.
312 .Ve
313 .PP
314 .Vb 1
315 \&    [...]
316 .Ve
317 .PP
318 .Vb 2
319 \&    For an up\-to\-date listing of CPAN sites, see
320 \&    http://www.perl.com/perl/ or ftp://ftp.perl.com/perl/ .
321 .Ve
322 .PP
323 Within the \s-1CPAN\s0 archive, AppConfig is in the category:
324 .PP
325 .Vb 1
326 \&    12) Option, Argument, Parameter and Configuration File Processing
327 .Ve
328 .PP
329 The module is available in the following directories:
330 .PP
331 .Vb 2
332 \&    /modules/by\-module/AppConfig/AppConfig\-<version>.tar.gz
333 \&    /authors/id/ABW/AppConfig\-<version>.tar.gz
334 .Ve
335 .PP
336 AppConfig is distributed as a single gzipped tar archive file:
337 .PP
338 .Vb 1
339 \&    AppConfig\-<version>.tar.gz
340 .Ve
341 .PP
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.
345 .PP
346 Unpack the archive to create a AppConfig installation directory:
347 .PP
348 .Vb 2
349 \&    gunzip AppConfig\-<version>.tar.gz
350 \&    tar xvf AppConfig\-<version>.tar
351 .Ve
352 .PP
353 \&'cd' into that directory, make, test and install the modules:
354 .PP
355 .Vb 5
356 \&    cd AppConfig\-<version>
357 \&    perl Makefile.PL
358 \&    make
359 \&    make test
360 \&    make install
361 .Ve
362 .PP
363 The 't' sub-directory contains a number of test scripts that are run when 
364 a 'make test' is run.
365 .PP
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
372 library location:
373 .PP
374 .Vb 1
375 \&    use lib '/local/path/to/lib';
376 .Ve
377 .PP
378 The 'examples' sub-directory contains some simple examples of using the 
379 AppConfig modules.
380 .SH "DESCRIPTION"
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:
386 .PP
387 .Vb 1
388 \&     use AppConfig;
389 .Ve
390 .PP
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:
393 .PP
394 .Vb 1
395 \&    use AppConfig qw(:expand :argcount);
396 .Ve
397 .PP
398 See \*(L"\s-1CONSTANT\s0 \s-1DEFINITIONS\s0\*(R" below for more information on the constant
399 tagsets defined by AppConfig.
400 .PP
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 
404 object.
405 .PP
406 .Vb 1
407 \&    my $config = AppConfig\->new();
408 .Ve
409 .PP
410 This will create and return a reference to a new AppConfig object.
411 .PP
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.  
416 .PP
417 The first (optional) parameter may be a reference to a hash array
418 containing configuration information.  
419 .PP
420 .Vb 8
421 \&    my $config = AppConfig\->new( {
422 \&            CASE   => 1,
423 \&            ERROR  => \e&my_error,
424 \&            GLOBAL => { 
425 \&                    DEFAULT  => "<unset>", 
426 \&                    ARGCOUNT => ARGCOUNT_ONE,
427 \&                },
428 \&        } );
429 .Ve
430 .PP
431 See AppConfig::State for full details of the configuration options
432 available.  These are, in brief:
433 .IP "\s-1CASE\s0" 4
434 .IX Item "CASE"
435 Used to set case sensitivity for variable names (default: off).
436 .IP "\s-1CREATE\s0" 4
437 .IX Item "CREATE"
438 Used to indicate that undefined variables should be created automatically
439 (default: off).
440 .IP "\s-1GLOBAL\s0" 4
441 .IX Item "GLOBAL"
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
444 and \s-1ACTION\s0.
445 .IP "\s-1PEDANTIC\s0" 4
446 .IX Item "PEDANTIC"
447 Used to indicate that command line and configuration file parsing routines
448 should return immediately on encountering an error.
449 .IP "\s-1ERROR\s0" 4
450 .IX Item "ERROR"
451 Used to provide a error handling routine.  Arguments as per \fIprintf()\fR.
452 .PP
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".
455 .PP
456 .Vb 2
457 \&    my $config = AppConfig\->new("foo", "bar", "baz");
458 \&    my $config = AppConfig\->new( { CASE => 1 }, qw(foo bar baz) );
459 .Ve
460 .PP
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:
465 .PP
466 .Vb 2
467 \&    # create AppConfig
468 \&    my $config = AppConfig\->new('foo', 'bar');
469 .Ve
470 .PP
471 .Vb 5
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);
477 .Ve
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.
482 .PP
483 .Vb 1
484 \&    $config\->define("foo");
485 .Ve
486 .PP
487 Variables may also be defined directly from the AppConfig \fInew()\fR
488 constructor.
489 .PP
490 .Vb 1
491 \&    my $config = AppConfig\->new("foo");
492 .Ve
493 .PP
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:
497 .PP
498 .Vb 4
499 \&    $config\->define("foo", {
500 \&            DEFAULT   => 99,
501 \&            ALIAS     => 'metavar1',
502 \&        });
503 .Ve
504 .PP
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.
507 .PP
508 .Vb 6
509 \&    my $config = AppConfig\->new( { 
510 \&        GLOBAL => {
511 \&            DEFAULT  => "<undef>",
512 \&            ARGCOUNT => ARGCOUNT_ONE,
513 \&        }
514 \&    } );
515 .Ve
516 .PP
517 .Vb 2
518 \&    $config\->define("foo");
519 \&    $config\->define("bar", { ARGCOUNT => ARGCOUNT_NONE } );
520 .Ve
521 .PP
522 is equivalent to:
523 .PP
524 .Vb 1
525 \&    my $config = AppConfig\->new();
526 .Ve
527 .PP
528 .Vb 4
529 \&    $config\->define( "foo", {
530 \&        DEFAULT  => "<undef>",
531 \&        ARGCOUNT => ARGCOUNT_ONE,
532 \&    } );
533 .Ve
534 .PP
535 .Vb 4
536 \&    $config\->define( "bar", 
537 \&        DEFAULT  => "<undef>",
538 \&        ARGCOUNT => ARGCOUNT_NONE,
539 \&    } );
540 .Ve
541 .PP
542 Multiple variables may be defined in the same call to \fIdefine()\fR.
543 Configuration hashes for variables can be omitted.
544 .PP
545 .Vb 1
546 \&    $config\->define("foo", "bar" => { ALIAS = "boozer" }, "baz");
547 .Ve
548 .PP
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
552 .IX Item "DEFAULT"
553 The default value for the variable (default: undef).
554 .IP "\s-1ALIAS\s0" 4
555 .IX Item "ALIAS"
556 One or more (list reference or \*(L"list|like|this\*(R") alternative names for the
557 variable.
558 .IP "\s-1ARGCOUNT\s0" 4
559 .IX Item "ARGCOUNT"
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.
565 .IP "\s-1ARGS\s0" 4
566 .IX Item "ARGS"
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
572 .IX Item "EXPAND"
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:
575 .Sp
576 .Vb 5
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.
582 .Ve
583 .IP "\s-1VALIDATE\s0" 4
584 .IX Item "VALIDATE"
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
588 .IX Item "ACTION"
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:
594 .PP
595 .Vb 1
596 \&    "name|alias|alias<argopts>"
597 .Ve
598 .PP
599 The first element indicates the variable name and subsequent \s-1ALIAS\s0 
600 values may be added, each separated by a vertical bar '|'.
601 .PP
602 The <argopts> element indicates the \s-1ARGCOUNT\s0 value and may be one of 
603 the following;
604 .PP
605 .Vb 4
606 \&    !                  ARGCOUNT_NONE
607 \&    =s                 ARGCOUNT_ONE
608 \&    =s@                ARGCOUNT_LIST
609 \&    =s%                ARGCOUNT_HASH
610 .Ve
611 .PP
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.  
616 .PP
617 The following examples demonstrate use of the comapct format, with their
618 equivalent full specifications:
619 .PP
620 .Vb 1
621 \&    $config\->define("foo|bar|baz!");
622 .Ve
623 .PP
624 .Vb 5
625 \&    $config\->define(
626 \&            "foo" => { 
627 \&                ALIAS    => "bar|baz", 
628 \&                ARGCOUNT => ARGCOUNT_NONE,
629 \&            });
630 .Ve
631 .PP
632 .Vb 1
633 \&    $config\->define("name=s");
634 .Ve
635 .PP
636 .Vb 4
637 \&    $config\->define(
638 \&            "name" => { 
639 \&                ARGCOUNT => ARGCOUNT_ONE,
640 \&            });
641 .Ve
642 .PP
643 .Vb 1
644 \&    $config\->define("file|filelist|f=s@");
645 .Ve
646 .PP
647 .Vb 5
648 \&    $config\->define(
649 \&            "file" => { 
650 \&                ALIAS    => "filelist|f", 
651 \&                ARGCOUNT => ARGCOUNT_LIST,
652 \&            });
653 .Ve
654 .PP
655 .Vb 1
656 \&    $config\->define("user|u=s%");
657 .Ve
658 .PP
659 .Vb 5
660 \&    $config\->define(
661 \&            "user" => { 
662 \&                ALIAS    => "u", 
663 \&                ARGCOUNT => ARGCOUNT_HASH,
664 \&            });
665 .Ve
666 .PP
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.
670 .PP
671 .Vb 1
672 \&    $config\->define("file|filelist|f=s@", { VALIDATE = \e&check_file() } );
673 .Ve
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 
677 values
678 .PP
679 .Vb 2
680 \&    set($variable, $value);
681 \&    get($variable);
682 .Ve
683 .PP
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.
686 .PP
687 .Vb 1
688 \&    $config\->set("verbose", 1);
689 .Ve
690 .PP
691 is equivalent to 
692 .PP
693 .Vb 1
694 \&    $config\->verbose(1);
695 .Ve
696 .PP
697 Note that AppConfig defines the following methods:
698 .PP
699 .Vb 4
700 \&    new();
701 \&    file();
702 \&    args();
703 \&    getopt();
704 .Ve
705 .PP
706 And also, through delegation to AppConfig::State:
707 .PP
708 .Vb 4
709 \&    define()
710 \&    get()
711 \&    set()
712 \&    varlist()
713 .Ve
714 .PP
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.
717 .PP
718 .Vb 1
719 \&    $config\->file();
720 .Ve
721 .PP
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:
725 .PP
726 .Vb 1
727 \&    $config\->get('file');
728 .Ve
729 .PP
730 or by defining a \*(L"safe\*(R" alias by which the variable can be accessed:
731 .PP
732 .Vb 3
733 \&    $config\->define("file", { ALIAS => "fileopt" });
734 \&or
735 \&    $config\->define("file|fileopt");
736 .Ve
737 .PP
738 .Vb 2
739 \&    ...
740 \&    $config\->fileopt();
741 .Ve
742 .PP
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.
746 .PP
747 .Vb 2
748 \&    $config\->age(29);        # sets 'age' to 29, returns 1 (ok)
749 \&    print $config\->age();    # prints "29"
750 .Ve
751 .PP
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. 
755 .PP
756 .Vb 1
757 \&    my %vars = $config\->varlist("^file");   # all "file*" variables
758 .Ve
759 .PP
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.
763 .PP
764 .Vb 2
765 \&    $config\->file_name("/tmp/file");
766 \&    $config\->file_path("/foo:/bar:/baz");
767 .Ve
768 .PP
769 .Vb 1
770 \&    my %vars = $config\->varlist("^file_", 1);
771 .Ve
772 .PP
773 .Vb 3
774 \&    # %vars:
775 \&    #    name => /tmp/file
776 \&    #    path => "/foo:/bar:/baz"
777 .Ve
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.  
786 .PP
787 .Vb 1
788 \&    $config\->file($filename);
789 .Ve
790 .PP
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.
793 .PP
794 .Vb 1
795 \&    $config\->file($filename, $filehandle, \e*STDIN, ...);
796 .Ve
797 .PP
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 
800 a '\e'.
801 .PP
802 .Vb 5
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
808 .Ve
809 .PP
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.
815 .PP
816 .Vb 7
817 \&    verbose                              # on  (1)
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)
824 .Ve
825 .PP
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.
830 .PP
831 .Vb 2
832 \&    room = /home/kitchen     
833 \&    room   /home/bedroom
834 .Ve
835 .PP
836 Each subsequent re-definition of the variable value overwrites the previous
837 value.
838 .PP
839 .Vb 1
840 \&    print $config\->room();               # prints "/home/bedroom"
841 .Ve
842 .PP
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.  
846 .PP
847 .Vb 2
848 \&    drink = coffee
849 \&    drink = tea
850 .Ve
851 .PP
852 A reference to a list of values is returned when the variable is requested.
853 .PP
854 .Vb 2
855 \&    my $beverages = $config\->drinks();
856 \&    print join(", ", @$beverages);      # prints "coffee, tea"
857 .Ve
858 .PP
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.
861 .PP
862 .Vb 2
863 \&    alias l="ls \-CF"
864 \&    alias e="emacs"
865 .Ve
866 .PP
867 A reference to the hash is returned when the variable is requested.
868 .PP
869 .Vb 4
870 \&    my $aliases = $config\->alias();
871 \&    foreach my $k (keys %$aliases) {
872 \&        print "$k => $aliases\->{ $k }\en";
873 \&    }
874 .Ve
875 .PP
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
878 .PP
879 .Vb 2
880 \&    \-verbose
881 \&    +debug
882 .Ve
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.
889 .PP
890 Three different expansion types may be applied:
891 .PP
892 .Vb 2
893 \&    bin = ~/bin          # expand '~' to home dir if EXPAND_UID
894 \&    tmp = ~abw/tmp       # as above, but home dir for user 'abw'
895 .Ve
896 .PP
897 .Vb 2
898 \&    perl = $bin/perl     # expand value of 'bin' variable if EXPAND_VAR
899 \&    ripl = $(bin)/ripl   # as above with explicit parens
900 .Ve
901 .PP
902 .Vb 1
903 \&    home = ${HOME}       # expand HOME environment var if EXPAND_ENV
904 .Ve
905 .PP
906 See AppConfig::State for more information on expanding variable values.
907 .PP
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 
913 file.
914 .PP
915 .Vb 2
916 \&    [block1]
917 \&    foo = 10             # block1_foo = 10
918 .Ve
919 .PP
920 .Vb 2
921 \&    [block2]
922 \&    foo = 20             # block2_foo = 20
923 .Ve
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.  
933 .PP
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 
938 arguments.  
939 .PP
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.
942 .PP
943 .Vb 2
944 \&    $config\->args(\e@myargs);
945 \&    $config\->args();               # uses @ARGV
946 .Ve
947 .PP
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.
952 .PP
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.
959 .PP
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
962 set its value to 0.
963 .PP
964 .Vb 3
965 \&    myprog \-verbose \-\-debug \-notaste     # $config\->verbose(1)
966 \&                                         # $config\->debug(1)
967 \&                                         # $config\->taste(0)
968 .Ve
969 .PP
970 Variables that expect an additional argument (\s-1ARGCOUNT\s0 != 0) will be set to 
971 the value of the argument following it.  
972 .PP
973 .Vb 1
974 \&    myprog \-f /tmp/myfile                # $config\->file('/tmp/file');
975 .Ve
976 .PP
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
979 is encountered.
980 .PP
981 .Vb 2
982 \&    myprog \-file /tmp/foo \-file /tmp/bar # $config\->file('/tmp/foo')
983 \&                                         # $config\->file('/tmp/bar')
984 .Ve
985 .PP
986 .Vb 1
987 \&    # file => [ '/tmp/foo', '/tmp/bar' ]
988 .Ve
989 .PP
990 .Vb 3
991 \&    myprog \-door "jim=Jim Morrison" \-door "ray=Ray Manzarek"
992 \&                                    # $config\->door("jim=Jim Morrison");
993 \&                                    # $config\->door("ray=Ray Manzarek");
994 .Ve
995 .PP
996 .Vb 1
997 \&    # door => { 'jim' => 'Jim Morrison', 'ray' => 'Ray Manzarek' }
998 .Ve
999 .PP
1000 See AppConfig::Args for further details on parsing command line
1001 arguments.
1002 .PP
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.
1006 .PP
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 
1010 default.
1011 .PP
1012 .Vb 4
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);
1017 .Ve
1018 .PP
1019 See Getopt::Long for details of the configuration options available.
1020 .PP
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.
1025 .PP
1026 .Vb 4
1027 \&    $config\->define("foo", {
1028 \&        ARGS  => "=i",
1029 \&        ALIAS => "bar|baz",
1030 \&    });
1031 .Ve
1032 .PP
1033 .Vb 1
1034 \&    # Getopt::Long specification: "foo|bar|baz=i"
1035 .Ve
1036 .PP
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.
1040 .PP
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.
1050 .PP
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 
1054 equals sign:
1055 .PP
1056 .Vb 1
1057 \&    http://www.here.com/cgi\-bin/myscript?foo=bar&baz=qux&verbose
1058 .Ve
1059 .PP
1060 .Vb 3
1061 \&        # $config\->foo('bar');
1062 \&        # $config\->baz('qux');
1063 \&        # $config\->verbose(1);
1064 .Ve
1065 .PP
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.
1070 .PP
1071 .Vb 1
1072 \&    http://where.com/mycgi?title=%22The+Wrong+Trousers%22
1073 .Ve
1074 .PP
1075 .Vb 1
1076 \&    # $config\->title('"The Wrong Trousers"');
1077 .Ve
1078 .PP
1079 Please be considerate of the security implications of providing writeable
1080 access to script variables via \s-1CGI\s0.
1081 .PP
1082 .Vb 2
1083 \&    http://rebel.alliance.com/cgi\-bin/...
1084 \&        .../send_report?file=%2Fetc%2Fpasswd&email=darth%40empire.com
1085 .Ve
1086 .PP
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.
1091 .PP
1092 .Vb 2
1093 \&    $config\->define('verbose', 'debug')
1094 \&    $config\->cgi();             # can only set verbose and debug
1095 .Ve
1096 .PP
1097 .Vb 2
1098 \&    $config\->define('email', 'file');
1099 \&    $config\->file($cfgfile);    # can set verbose, debug, email + file
1100 .Ve
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.
1108 .PP
1109 .Vb 1
1110 \&    use AppConfig qw(ARGCOUNT_NONE ARGCOUNT_ONE);
1111 .Ve
1112 .PP
1113 .Vb 1
1114 \&    use AppConfig qw(:argcount);
1115 .Ve
1116 .PP
1117 The following tag sets are defined:
1118 .IP ":expand" 4
1119 .IX Item ":expand"
1120 The ':expand' tagset defines the following constants:
1121 .Sp
1122 .Vb 6
1123 \&    EXPAND_NONE
1124 \&    EXPAND_VAR
1125 \&    EXPAND_UID 
1126 \&    EXPAND_ENV
1127 \&    EXPAND_ALL       # EXPAND_VAR | EXPAND_UID | EXPAND_ENV
1128 \&    EXPAND_WARN
1129 .Ve
1130 .Sp
1131 See AppConfig::File for full details of the use of these constants.
1132 .IP ":argcount" 4
1133 .IX Item ":argcount"
1134 The ':argcount' tagset defines the following constants:
1135 .Sp
1136 .Vb 4
1137 \&    ARGCOUNT_NONE
1138 \&    ARGCOUNT_ONE
1139 \&    ARGCOUNT_LIST 
1140 \&    ARGCOUNT_HASH
1141 .Ve
1142 .Sp
1143 See AppConfig::State for full details of the use of these constants.
1144 .SH "AUTHOR"
1145 .IX Header "AUTHOR"
1146 Andy Wardley, <abw@wardley.org>
1147 .PP
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
1150 welcome).
1151 .SH "COPYRIGHT"
1152 .IX Header "COPYRIGHT"
1153 Copyright (C) 1997\-2007 Andy Wardley.  All Rights Reserved.
1154 .PP
1155 Copyright (C) 1997,1998 Canon Research Centre Europe Ltd.
1156 .PP
1157 This module is free software; you can redistribute it and/or modify it 
1158 under the same terms as Perl itself.
1159 .SH "SEE ALSO"
1160 .IX Header "SEE ALSO"
1161 AppConfig::State, AppConfig::File, AppConfig::Args, AppConfig::Getopt,
1162 AppConfig::CGI, Getopt::Long