Sendpage::KeesConf(3pm) | User Contributed Perl Documentation | Sendpage::KeesConf(3pm) |
Sendpage::KeesConf - implements a configuration file reader
use Sendpage::KeesConf; $config = Sendpage::KeesConf->new(); $config->define("variable", { DEFAULT => "setting" }); $config->file("config.cfg"); $setting=$config->get("variable");
I have borrowed VERY heavily from Andy Wardley's (abw@cre.canon.co.uk) "AppConfig" tool, which can be found on CPAN (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.
The following methods are available:
$options can contain:
That way, global variables can be overridden by section-specific variables. If "SECTION:Instance@name" does not exist, "name" will be tried.
[SECTION:INSTANCE] VARIABLE1 = VALUE1 VARIABLE2 = VALUE2 . . .
If VARIABLE is an array, VALUE is loaded using commas (,) as the list separator. The variable will be available under the name of the section. For example, to see VALUE2, it would be accessed as:
$config->get("SECTION:INSTANCE\@VARIABLE2");
Notice, that "=", ":", and "@" are all not allowed in section or variable names.
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:
$config->define("modem:baud",{ DEFAULT => 9600 }); $config->define("modem:flowctl",{ DEFAULT => "hardware" });
Then, when you load them, let's say the config file has:
[modem:sportster] baud = 115200 [modem:hayes]
The baud rate for the sportster will come back as 115200, but the hayes will fall back during a "get" call, and find the default for the modem section: 9600. Both fallback to have "flowctl" as "hardware":
# returns specific value 115200 $config->get("modem:sportster\@baud"); # returns default value 9600 $config->get("modem:hayes\@baud"); # both return default value "hardware" $config->get("modem:sportster\@flowctl"); $config->get("modem:hayes\@flowctl");
Kees Cook <kees@outflux.net>
perl(1), sendpage(1), Sendpage::KeesLog(3), Sendpage::Modem(3), Sendpage::PagingCentral(3), Sendpage::PageQueue(3), Sendpage::Page(3), Sendpage::Recipient(3), Sendpage::Queue(3)
Copyright 2000 Kees Cook.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2008-01-03 | perl v5.10.0 |