.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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" '' . ds C` . ds C' '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 >0, 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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Sendpage::KeesConf 3pm" .TH Sendpage::KeesConf 3pm "2021-01-08" "perl v5.32.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\->\fBnew()\fR;" 4 .el .IP "\f(CW$config\fR = Sendpage::KeesConf\->\fBnew()\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\->\fBforget()\fR;" 4 .el .IP "\f(CW$config\fR\->\fBforget()\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" \&\fBperl\fR\|(1), \fBsendpage\fR\|(1), \fBSendpage::KeesLog\fR\|(3), \fBSendpage::Modem\fR\|(3), \&\fBSendpage::PagingCentral\fR\|(3), \fBSendpage::PageQueue\fR\|(3), \fBSendpage::Page\fR\|(3), \&\fBSendpage::Recipient\fR\|(3), \fBSendpage::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. .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR .IP "Around line 119:" 4 .IX Item "Around line 119:" Expected text after =item, not a number .IP "Around line 123:" 4 .IX Item "Around line 123:" Expected text after =item, not a number