Configuration 4 GNU (CFG)


Backend

Prev   Next

The backend consists primarily of parsers which are responsible for the translation between XML and the native config files. The parsers may be written in any language, however it is strongly encouraged to use Perl because nearly all *nix systems have Perl, and a useful Perl module exists which handles many common tasks in a uniform way. To add support for a new configuration entity, an existing parser can often be extended with minimal effort, leaving only the task of creating type definitions for your parser's XML.

[Note]Note

When referring to parsers, often the CFGXML::Parser:: beginning of the parser's full module name is omitted for readability.

Extending the Parser Backend

The existing CFGXML::Parser, config4gnu::CfgObject, and related Perl modules provide many functions and options which handle most of the work for you. For reference, if your parser is more than 200 lines at most then you're probably either not using the libraries to the extent you could be, or you should put some of your code into functions and submit them for inclusion in the standard CFGXML::Parser module.

To create a new parser, one of two approaches can be used. Either subclass an existing Perl parser using Perl's inheritance system or write a completely new parser from scratch. Generally, you should use the first approach if a parser for the configuration file format that you're adding already exists, for example the App::Samba::Default parser was created by extending the Common::Ini parser which handles the INI-style formatted configuration files.

If no parser for the format you need exists create two parsers, the generic parser for the format (i.e., INI), and the parser for the particular application which you are adding support for. Generally the generic parser goes in CFGXML::Parser::Common::YourFormat and the specific parser goes in either CFGXML::Parser::App or CFGXML::Parser::Distro. Doing this takes little extra work but allows others to extend your base parser for other applications.

Prev Up Next
Frontend Home CFGXML::Parser Module

SourceForge Logo