AddDirective
Define a new configuration directive.
Synopsis
|
AddDirective name parser default
|
Scope
This directive is only available for use in the global
(interchange.cfg) configuration file,
and will affect all websites running under the Interchange installation.
It will not work in a website's local (catalog.cfg)
configuration file.
Description
This directive defines a new configuration directive that will be
valid in every catalog.cfg file defined within the current
Interchange installation instance.
AddDirective has three parameters, as follows:
- The name of the directive.
- The name of the parser subroutine.
- The default if no value is provided when the directive is called.
The following definition would add a directive called "Foo",
with "parse_bar" as the parser subroutine.
|
AddDirective Foo bar "default value"
|
If the parser is not defined,
or defined as "undef",
then the directive value will be the scalar (string)
value passed to the directive in the catalog.cfg
configuration file.
The scalar will be assigned the default value unless the
custom directive is called with an overriding value.
If defined, the parser must exist in the Vend::Config
namespace, with a "parse_" prefix, before it can be referenced.
Interchange supplies a number of pre-defined "parse_" subroutines
that you can re-use with with your new directive.
See Interchange's Vend::Config module source for a list.
To make use of a pre-defined "parse_" subroutine,
simply pass its name to AddDirective,
as the parser parameter,
without the leading "parse_" part of the name.
|
Note
Parser subroutines must be declared to Sub
or GlobalSub with a "parse_" prefix,
but the "parse_" prefix must not be passed to
AddDirective.
See the example, below.
|
|
Warning
The parser subroutine must be declared,
using a Sub or GlobalSub directive,
before the AddDirective attempts to make use of it.
|
Example
The following is a simple example of how to define a new configuration
directive, along with its associated parser subroutine:
GlobalSub <<EOS
sub declare_extra_config {
package Vend::Config;
sub parse_mynewconfig {
my ($directive, $value) = @_;
::logGlobal("directive=$directive, value=$value");
1;
}
}
EOS
AddDirective MyNewConfig mynewconfig "Default value"
|
The new (local) configuration directive may now be used in a
website's catalog.cfg file as follows: