PSP::Config - the configuration object class for the Perl Script Pages (PSP) interface, engine and supporting modules.
use PSP::Config; my $conf = new PSP::Config( file => $filename, hash => { key1 => $value1, key2 => $value2 } ); my $value = $conf->get($key); my $value = $conf->{$key}; my $success = $conf->add($key,$value); my $success = $conf->addHash(\%hash); my $success = $conf->addHash( { key1 => 'value', key_array => ['value2', 'value3'] } ); my $success = $conf->addFile($filename);
This modules provides default configuration values, methods for setting and accessing configuration data and loading configuration from files. This module was created as a companion to the Perl Script Pages Engine. See the PSP::Engine manpage for more information.
Creates a new PSP::Config object with default values. Optional a file to load configuration from or a configuration hash may be passed to the constructor. For file format definitions see addFile method. For hash format definitions see addHash method.
use PSP::Config; my $conf = new PSP::Config( file => $filename, hash => \%hash ); use PSP::Config; my $conf = new PSP::Config( hash => { key1 => $value1, key2 => $value2 } );
None.
The following parameters are key/value hash parameters.
Receive a configuration value for a given key from the configuration data.
my $value = $conf->get($key);
You may also access the configuration data directly via the object.
my $value = $conf->{$key};
None.
Adds a single configuration key/value set to the configuration data.
my $success = $conf->add($key,$value);
If $key describes a simple scalar configuration directive, $value replaces the default. If $key is an array configuration directive, $value is appended to the corresponding values array.
$value may contain special @@string@@
macros that are replaced by
environment valiables, for example @@DOCUMENT_ROOT@@
will be replaced by the
content of the $DOCUMENT_ROOT
environment variable, i.e. ``/var/www/html/''.
None.
Adds a referenced hash or an anonymous hash to the configuration data.
my $success = $conf->addHash($hashref);
my %hash = ( key1 => 'value', key_array => ['value2', 'value3'] ); my $success = $conf->addHash(\%hash); my $success = $conf->addHash( { key1 => 'value', key_array => ['value2', 'value3'] } );
The hash elements can either be standard ``key => $value'' parameters that call the add method once or ``key => [$value1, $value2]'' ordered array parameters that call the add method for every value in the array but always for the same key.
Values may contain environment variable macros. See add method for details.
None.
Loads data from a file and adds it to the object's configuration data.
my $success = $conf->addFile($filename);
Configuration files are ordinary text files and may contain lines of the format
ThisIsTheKey=This is a value
, terminated by \n or \r\n.
The system interpretes everything left of the first ``='' character as the key,
everything on the right as configuration value, so both key and value parts may
contain i.e. spaces, value even may contain the ``='' character without quoting
or escaping.
Empty lines and lines beginning with ``#'' (comments) are ignored.
Values may contain environment variable macros. See add method for details.
None.
Veit Wahlich
E-Mail: cru |at| zodia |dot| de
WWW: http://home.ircnet.de/cru/
v0.7 Wednesday, 18 January 2006
Copyright 2004-2006 Veit Wahlich
This software is distributed as free (libre) software under the terms of the GNU General Public License, version 2 <http://www.gnu.org/copyleft/gpl.html>. The author disclaims responsibility of any damage or harm caused directly or indirectly by usage of this software. Use only at your own risk.