Config::Dot - Module for simple configure file parsing.
use Config::Dot; my $cnf = Config::Dot->new(%params); my $struct_hr = $cnf->parse($string); $cnf->reset; my $serialized = $cnf->serialize;
new
my $cnf = Config::Dot->new(%params);
Constructor.
callback
Callback code for adding parameter.
Callback arguments are:
$key_ar
Reference to array with keys.
$value
Key value.
Default is undef.
config
Reference to hash structure with default config data. This is hash of hashes structure.
Default value is reference to blank hash.
set_conflicts
Set conflicts detection as error.
Default value is 1.
Returns instance of object.
parse
my $struct_hr = $cnf->parse($string);
Parse string $string_or_array_ref or reference to array $string_or_array_ref. Use $INPUT_RECORD_SEPARATOR variable to split lines.
$string_or_array_ref
$INPUT_RECORD_SEPARATOR
Returns hash structure with configuration.
reset
$cnf->reset;
Reset content in class (config parameter).
Returns undef.
serialize
my $serialized = $cnf->serialize;
Serialize 'config' hash to output. Use $INPUT_RECORD_SEPARATOR variable to join lines.
Returns string with serialized configuration.
# Comment. # blabla # White space. /^\s*$/ # Parameters. # Key must be '[-\w\.:,]+'. # Separator is '='. key=val key2.subkey.subkey=val
new(): Bad 'config' parameter. Parameter 'callback' isn't code reference. From Class::Utils::set_params(): Unknown parameter '%s'. parse(): Bad key '%s' in string '%s' at line '%s'. From Config::Utils::hash(): Conflict in '%s'. serialize(): Unsupported stay with newline in value.
use strict; use warnings; use Config::Dot; use Data::Printer; # Object. my $struct_hr = Config::Dot->new->parse(<<'END'); key1=value1 key2=value2 key3.subkey1=value3 END # Dump. p $struct_hr; # Output: # { # key1 "value1", # key2 "value2", # key3 { # subkey1 "value3" # } # }
use strict; use warnings; use Config::Dot; # Object with data. my $c = Config::Dot->new( 'config' => { 'key1' => { 'subkey1' => 'value1', }, 'key2' => 'value2', }, ); # Serialize. print $c->serialize."\n"; # Output: # key1.subkey1=value1 # key2=value2
use strict; use warnings; use Config::Dot; use Data::Printer; # Object. my $struct_hr = Config::Dot->new( 'callback' => sub { my ($key_ar, $value) = @_; if ($key_ar->[0] eq 'key3' && $key_ar->[1] eq 'subkey1' && $value eq 'value3') { return 'FOOBAR'; } return $value; }, )->parse(<<'END'); key1=value1 key2=value2 key3.subkey1=value3 END # Dump. p $struct_hr; # Output: # { # key1 "value1", # key2 "value2", # key3 { # subkey1 "FOOBAR" # } # }
Class::Utils, Config::Utils, English, Error::Pure, Readonly.
Common config utilities.
Module for simple configure file parsing with arrays.
https://github.com/michal-josef-spacek/Config-Dot
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2011-2023 Michal Josef Špaček
BSD 2-Clause License
0.10
To install Config::Dot, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Dot
CPAN shell
perl -MCPAN -e shell install Config::Dot
For more information on module installation, please visit the detailed CPAN module installation guide.