Libconf::Templates::Generic::KeyValue - Libconf generic low level template for semantic association (KEY - VALUE) styles config files
Libconf::Templates::Generic::KeyValue is a generic template that handles config files that contain semantic informations of type : (KEY - VALUE).
$template = new Libconf::Templates::Generic::KeyValue({
filename => 'autologin',
separator_char => '=',
allow_space => 1,
comments_struct => [['#']],
handle_quote => 1,
handle_multiples_lines => 0,
handle_backslash => 1,
backslash_character => '\\',
accept_empty_value => 1,
});
$template->read_conf();
$template->edit_atom(-1, {key => 'USER' }, { value => 'plop'});
$template->edit_atom(-1, {key => 'AUTOLOGIN' }, { value => 'no'});
$template->edit_atom(-1, {key => 'EXEC' }, { value => 'startx'});
...
(see L<Libconf::Templates> for transformation methods on $template) ...
...
$template->write_conf("output_file");
creates the template
$template = new Libconf::Templates::Generic::KeyValue({
filename => 'some_file',
separator_char => '=',
output_separator_char => "\t",
allow_space => 1,
comments_struct => [['#']],
handle_quote => 1,
simplify_quote => 0,
handle_multiples_lines => 0,
handle_backslash => 1,
backslash_character => '\\',
accept_empty_value => 0,
})
arguments
$options [type : HASH_REF] specifies the options to create the new template instance.
options
filename [type : STRING, default : ''] : the filename of the config file you want to work on. Can be read and written lately by using set_filename and get_filename.
separator_char [type : STRING, default : '='] : the separator between key and value
output_separator_char [type : STRING, default : separator_char ] : the separator between key and value used to write the file back
allow_spaces [type : SCALAR, default : 1] : if true, space around separator_char are allowed and ignored if false, they are not allowed.
comments_struct [type : ARRAY_REF of ARRAY_REF of STRING,STRING,SCALAR, default : [['#']] ] : defines the type and the characters of comments. The structure is : [ [ comment1_open_char, comment1_close_char, comment1_nested 1], [ comment2_open_char, comment2_close_char, comment2_nested ], ... ]
open_char [type : STRING, default : '#'] : the character(s) that delimits the start of a comment
close_char [OPTIONAL, type : STRING] : the character that delimits the end of the comment. If ommited, the comment stops at the end of the line
nested [OPTIONAL, type : SCALAR] : if true, comments of comments are nested.
Example 1, one simple line comment with character # : [['#']]
Example 2, one simple line comment with character #, another simple line comment with ';' character, and the common C /* */ comment : [['#'], [';'], ['/*', '*/']]
Example 3, the common C /* */ comment, the C++ // comment, and the nested ocaml (* *) : [['/*', '*/'], ['//'], ['(*', '*)', 1]]
handle_quote [type : SCALAR, default : true] : if true, quotes are interpreted and removed from the value. When writing to the config file back, quotes are added if needed. if false, quotes are not interpreted, and present in the value.
simplify_quote [type : SCALAR, default : false] : if true, unneeded quotes are removed from the value. If not, they are kept as they were in the original file.
handle_multiples_lines [type : BOOLEAN, default : false] : if true, line that begins with a space character and that doesn't contain the separator_char, are taken as the continuation of the upper line
handle_backslash [type : BOOLEAN, default : false] : if true, line that ends with [backslash_character] are continued on the next line
backslash_character [type : STRING, default : \ ] : the character that is used by handle_backslash
accept_empty_value [type : BOOLEAN, default : true] : if true, lines where the value is not specified (like ``key='') are accepted, and the value is set to empty string. If set to false, such a line will trigger an error.
_input_function [type : FUNCTION_REF, default : undefined ] : if defined, it's used to parse. This function should behave as _parse_chunk. Don't use it unless you know it. See the source for more info about _parse_chunk
See Libconf::Templates for the general list of methods you can call on this template.
There is no specific method