SYNOPSIS

    use Sendpage::KeesConf;
    $config = Sendpage::KeesConf->new();

    $config->define("variable", { DEFAULT => "setting" });

    $config->file("config.cfg");

    $setting=$config->get("variable");

DESCRIPTION

I have borrowed \s-1VERY\s0 heavily from Andy Wardley's ([email protected]) \*(C`AppConfig\*(C' 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.

The following methods are available: The constructor doesn't take an arguement, but it should in the future. This call will make $config forget about any variables it has loaded. It does \s-1NOT\s0 forget \*(C`define\*(C'd variables, just instantiated ones via \*(C`file\*(C'. This will define a variable by the name of $name. $options can contain:

\s-1ARGCOUNT\s0

What type of variable this should be. Default value is \*(L"1\*(R". The available types are:

0

Boolean (true/false, yes/no, 1/0)

1

Scalar (any string)

2

List (an array of strings)

\s-1DEFAULT\s0

The default value the variable should have if it is not overridden during the call to \*(C`file\*(C'. The \s-1DEFAULT\s0 must be the same data type as \s-1ARGCOUNT\s0. The default \s-1DEFAULT\s0 is the string \*(L"<unset>\*(R".

\s-1UNSET\s0

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.

This tests to see if there is a section loaded named $name This call will search for the variable named $name. 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. This call will search for the variable named $name. 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". This call will search for the variable named $name. If it is not found, the section portion will be removed, and retried for a sectionless \*(L"get\*(R" call. 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. This call will search for the variable named $name. If it is not found, it will fall back to the default for the section. Sections are explained in more detail later. Returns an array of the names of all the variables in the class $class. Loads variables from the named file. Syntax for this file is: [SECTION:INSTANCE] VARIABLE1 = VALUE1 VARIABLE2 = VALUE2 . . . 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: $config->get("SECTION:INSTANCE\@VARIABLE2"); Notice, that \*(L"=\*(R", \*(L":\*(R", and \*(L"@\*(R" 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 \*(C`get\*(C' call, and find the default for the modem section: 9600. Both fallback to have \*(L"flowctl\*(R" as \*(L"hardware\*(R":

# 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");

CAVEATS

character limitations

As mentioned above, variable names (and section names) cannot have the characters \*(L":\*(R", \*(L"@\*(R", or \*(L"=\*(R" in them.

default defaults

There should be a way to pass default defaults into \*(C`new\*(C'. That would be handy, and could eliminate the need for the \s-1UNSET\s0 option in \*(C`define\*(C'.

AUTHOR

Kees Cook <[email protected]>

RELATED TO Sendpage::KeesConf…

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

Copyright 2000 Kees Cook.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.