|
NAMEConfig::Objective - Perl module for parsing object-oriented config filesSYNOPSISuse Config::Objective; use Config::Objective::String; use Config::Objective::List; my $conf = Config::Objective->new('filename', { 'var1' => Config::Objective::String->new(), 'var2' => Config::Objective::List->new(), ... }, 'include_dir' => '/usr/local/share/appname'); print "var1 = \"" . $conf->var1 . "\"\n"; DESCRIPTIONThe Config::Objective module provides a mechanism for parsing config files to manipulate configuration data. Unlike most other config file modules, which represent config data as simple variables, Config::Objective represents config data as perl objects. This allows for a much more flexible configuration language, since new classes can be easily written to add methods to the config syntax.The Config::Objective class supports the following methods:
CONFIG FILE SYNTAXThe config file format supported by Config::Objective is described here.Data TypesConfig::Objective supports three types of data: scalars, lists, and hashes. The syntax for these types is intentionally similar to their perl equivalents.
Configuration StatementsEach statement in the config file results in calling a method on a configuration object. The syntax is:object[->method] [args]; In this syntax, "object" is the name of the object. The object must be created and passed to the Config::Objective constructor, as described above. The "->method" portion is optional. If specified, it indicates which method should be called on the object. If not specified, a method called default() will be used. The "args" portion is also optional. It specifies one or more comma-delimited arguments to pass to the method. If multiple arguments are provided, the entire argument list must be enclosed in parentheses. Each argument can be a simple scalar, list, hash, or a complex, nested list or hash structure, as described above. So, putting this all together, here are some example configuration statements: ### call default method with no arguments object; ### call a specific method, but still no args object->method; ### call default method, but specify a single scalar argument object scalar_arg; ### call default method, but specify a single list argument object [ this, is, a, single, list, argument ]; ### call a specific method and specify a single hash argument object->method { this, is, a, single, hash, argument }; ### call a specific method with multiple scalar args object->method(arg1, arg2, arg3); ### call a specific method with multiple args of different types object->method(scalar_arg, [ list, argument ], { hash => argument }); Conditional EvaluationThe config syntax also provides some rudementary support for conditional evaluation. A conditional directive is signalled by the use of a "%" character at the beginning of a line (i.e., no leading whitespace). There can be space between the "%" and the conditional directive, however, which can improve readability when using nested conditional blocks.The conditional directives are %if, %else, %elif, and %endif . They can be used to enclose other config statements, which are evaluated or skipped based on whether the conditional expression evaluates to true. For example: %if ( expression ) ... other config directives ... %endif The most basic expression is simply a method call that returns a true or false value. The syntax for this is the same as a normal config statement, except without the trailing semicolon: %if ( object[->method] [args] ) If no method is specified, the equals() method will be called by default. Multiple expressions can be combined using the "&&", "||", and "!" operators. Additional parentheses can also be used for grouping within the expression. For example: %if ( ( object1 foo && ! object2 bar ) || object3 baz ) File InclusionFile inclusion is another type of conditional evaluation. It allows you to include another file in the config file that is currently being parsed, similar to the C preprocessor's "#include" directive. The syntax is:%include "filename" If the specified filename is not an absolute path, Config::Objective will look for it in the directory specified by the include_dir attribute when the Config::Objective object was created. Note that the %include directive will be ignored within an %if block whose condition is false. This means that you cannot start an %if block in one file, add a %include directive, and provide the %endif directive in the included file. All %if blocks must be fully contained within the same file. CommentsAny text between a "#" character and the next newline is considered a comment. The "#" character loses this special meaning if it is enclosed in a quoted string or immediately preceded by a "\".CONFIGURATION OBJECTSThis section explains the details of how configuration objects are used.Recommended MethodsThere are no strict requirements for how a class must be designed in order to be used for a configuration object. The following methods are recommended in that they will be used by Config::Objective in certain circumstances, but they do not need to be present if they are not actually going to be used.
Supplied Object ClassesConfig::Objective supplies several classes that can be used for encapsulating common types of configuration data.
See the documentation for each of these classes for more information. AUTHORMark D. Roth <roth@uiuc.edu>SEE ALSOperl.
Visit the GSP FreeBSD Man Page Interface. |