.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Sendpage::KeesConf 3pm" .TH Sendpage::KeesConf 3pm "2008-01-03" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Sendpage::KeesConf \- implements a configuration file reader .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Sendpage::KeesConf; \& $config = Sendpage::KeesConf\->new(); \& \& $config\->define("variable", { DEFAULT => "setting" }); \& \& $config\->file("config.cfg"); \& \& $setting=$config\->get("variable"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" I have borrowed \s-1VERY\s0 heavily from Andy Wardley's (abw@cre.canon.co.uk) \&\f(CW\*(C`AppConfig\*(C'\fR tool, which can be found on \s-1CPAN\s0 (http://cpan.perl.org) but I found it not dynamic enough for multi-instance variable defaults. As a result, I wrote this massively trimmed-down version for my use. .PP The following methods are available: .ie n .IP "$config = Sendpage::KeesConf\->\fInew()\fR;" 4 .el .IP "\f(CW$config\fR = Sendpage::KeesConf\->\fInew()\fR;" 4 .IX Item "$config = Sendpage::KeesConf->new();" The constructor doesn't take an arguement, but it should in the future. .ie n .IP "$config\->\fIforget()\fR;" 4 .el .IP "\f(CW$config\fR\->\fIforget()\fR;" 4 .IX Item "$config->forget();" This call will make \f(CW$config\fR forget about any variables it has loaded. It does \s-1NOT\s0 forget \f(CW\*(C`define\*(C'\fRd variables, just instantiated ones via \f(CW\*(C`file\*(C'\fR. .ie n .IP "$config\->define($name, $options);" 4 .el .IP "\f(CW$config\fR\->define($name, \f(CW$options\fR);" 4 .IX Item "$config->define($name, $options);" This will define a variable by the name of \f(CW$name\fR. .Sp \&\f(CW$options\fR can contain: .RS 4 .IP "\s-1ARGCOUNT\s0" 4 .IX Item "ARGCOUNT" What type of variable this should be. Default value is \*(L"1\*(R". The available types are: .RS 4 .IP "0" 4 Boolean (true/false, yes/no, 1/0) .IP "1" 4 .IX Item "1" Scalar (any string) .IP "2" 4 .IX Item "2" List (an array of strings) .RE .RS 4 .RE .IP "\s-1DEFAULT\s0" 4 .IX Item "DEFAULT" The default value the variable should have if it is not overridden during the call to \f(CW\*(C`file\*(C'\fR. The \s-1DEFAULT\s0 must be the same data type as \s-1ARGCOUNT\s0. The default \s-1DEFAULT\s0 is the string \*(L"\*(R". .IP "\s-1UNSET\s0" 4 .IX Item "UNSET" set this to 1 if you want the default value to be undefined. This is a hack to get around the default \s-1DEFAULT\s0. .RE .RS 4 .RE .ie n .IP "$config\->instance_exists($name);" 4 .el .IP "\f(CW$config\fR\->instance_exists($name);" 4 .IX Item "$config->instance_exists($name);" This tests to see if there is a section loaded named \f(CW$name\fR .ie n .IP "$var=$config\->ifset($name);" 4 .el .IP "\f(CW$var\fR=$config\->ifset($name);" 4 .IX Item "$var=$config->ifset($name);" This call will search for the variable named \f(CW$name\fR. If it is not found, it will return undef. If the value exists, it will return the value. This is a way to call \*(L"get\*(R" without having a default passed through. .ie n .IP "$var=$config\->exists($name);" 4 .el .IP "\f(CW$var\fR=$config\->exists($name);" 4 .IX Item "$var=$config->exists($name);" This call will search for the variable named \f(CW$name\fR. If it is not found, it will return false. If the value exists, it will return true. This is a way for the user to find out if they will get a \*(L"default\*(R" on a call to \*(L"get\*(R". .ie n .IP "$var=$config\->fallbackget($name,$quiet);" 4 .el .IP "\f(CW$var\fR=$config\->fallbackget($name,$quiet);" 4 .IX Item "$var=$config->fallbackget($name,$quiet);" This call will search for the variable named \f(CW$name\fR. If it is not found, the section portion will be removed, and retried for a sectionless \*(L"get\*(R" call. .Sp That way, global variables can be overridden by section-specific variables. If \*(L"SECTION:Instance@name\*(R" does not exist, \*(L"name\*(R" will be tried. .ie n .IP "$var=$config\->get($name);" 4 .el .IP "\f(CW$var\fR=$config\->get($name);" 4 .IX Item "$var=$config->get($name);" This call will search for the variable named \f(CW$name\fR. If it is not found, it will fall back to the default for the section. Sections are explained in more detail later. .ie n .IP "$config\->instances($class);" 4 .el .IP "\f(CW$config\fR\->instances($class);" 4 .IX Item "$config->instances($class);" Returns an array of the names of all the variables in the class \f(CW$class\fR. .ie n .IP "$config\->file('program.cfg');" 4 .el .IP "\f(CW$config\fR\->file('program.cfg');" 4 .IX Item "$config->file('program.cfg');" Loads variables from the named file. Syntax for this file is: .Sp .Vb 6 \& [SECTION:INSTANCE] \& VARIABLE1 = VALUE1 \& VARIABLE2 = VALUE2 \& . \& . \& . .Ve .Sp If \s-1VARIABLE\s0 is an array, \s-1VALUE\s0 is loaded using commas (,) as the list separator. The variable will be available under the name of the section. For example, to see \s-1VALUE2\s0, it would be accessed as: .Sp .Vb 1 \& $config\->get("SECTION:INSTANCE\e@VARIABLE2"); .Ve .Sp Notice, that \*(L"=\*(R", \*(L":\*(R", and \*(L"@\*(R" are all not allowed in section or variable names. .PP Sections can be defined (and loaded) so that defaults can pass back to a defined section default. For example, lets say that you have several modems, and most of them have different settings. You can define all the modem variables like so: .PP .Vb 2 \& $config\->define("modem:baud",{ DEFAULT => 9600 }); \& $config\->define("modem:flowctl",{ DEFAULT => "hardware" }); .Ve .PP Then, when you load them, let's say the config file has: .PP .Vb 2 \& [modem:sportster] \& baud = 115200 \& \& [modem:hayes] .Ve .PP The baud rate for the sportster will come back as 115200, but the hayes will fall back during a \f(CW\*(C`get\*(C'\fR call, and find the default for the modem section: 9600. Both fallback to have \*(L"flowctl\*(R" as \*(L"hardware\*(R": .PP .Vb 2 \& # returns specific value 115200 \& $config\->get("modem:sportster\e@baud"); \& \& # returns default value 9600 \& $config\->get("modem:hayes\e@baud"); \& \& # both return default value "hardware" \& $config\->get("modem:sportster\e@flowctl"); \& $config\->get("modem:hayes\e@flowctl"); .Ve .SH "CAVEATS" .IX Header "CAVEATS" .IP "character limitations" 4 .IX Item "character limitations" As mentioned above, variable names (and section names) cannot have the characters \*(L":\*(R", \*(L"@\*(R", or \*(L"=\*(R" in them. .IP "default defaults" 4 .IX Item "default defaults" There should be a way to pass default defaults into \f(CW\*(C`new\*(C'\fR. That would be handy, and could eliminate the need for the \s-1UNSET\s0 option in \f(CW\*(C`define\*(C'\fR. .SH "AUTHOR" .IX Header "AUTHOR" Kees Cook .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIperl\fR\|(1), \fIsendpage\fR\|(1), \fISendpage::KeesLog\fR\|(3), \fISendpage::Modem\fR\|(3), \&\fISendpage::PagingCentral\fR\|(3), \fISendpage::PageQueue\fR\|(3), \fISendpage::Page\fR\|(3), \&\fISendpage::Recipient\fR\|(3), \fISendpage::Queue\fR\|(3) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2000 Kees Cook. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.