Pattern Configuration
It is sometimes useful to permit the end-user to modify certain characteristics of a pattern, such as whether to enable features that might be costly, or to change a set of default paths or package names. This is enabled with pattern configuration blocks. Pattern configuration is new in TPL 1.2.
Configuration block definition
configuration blocks are top-level elements. Like other elements, they have a name and a version number. Pattern modules can import configuration blocks from other modules, using the usual version numbering conventions.
The form of a configuration block is:
"""
_Description of configuration block to show in UI_
"""
"_Description of first configuration item_"
_config_name_ := _config_value_;
...
*end configuration*;
Configuration items are given a human-readable description to be shown in the user interface, an identifier to use in patterns, and a default value. The default value is the value used if the configuration item has not been changed by the user. It also determines the type of the configuration item — the user interface will only allow the user to change the setting to a value with the same type. The valid types for configuration items are text string, integer, boolean, list of strings, and list of integers.
This example shows a number of configuration settings:
"""
An example configuration block.
"""
"A boolean flag"
a_flag := true;
"Command to run"
command := "sudo rm -rf /";
"Port for the service"
port := 12345;
"Paths to look in"
paths := [ "/usr/bin", "/usr/local/bin" ];
*end configuration*;
Using configuration settings
Configuration settings are used in patterns by giving the scoped name of the configuration block, followed by the configuration setting name:
result := discovery.runCommand(host, MyConfig.command);
*end if*
Types of default empty lists
The types of configurations items can usually be inferred from the type of the default value. However, if the default value of a configuration item is an empty list, the system cannot know whether it is a list of text strings or a list of integers. To tell the system the type of such a configuration item, an example of the type should be provided in parentheses after the empty list:
empty_string_list := [ ] ("");
"This is a list of integers that's empty by default"
empty_number_list := [ ] (0);