Config::Dot::Array - Module for simple configure file parsing with arrays.
my $cnf = Config::Dot::Array->new(%params); my $struct_hr = $cnf->parse($string_or_array_ref); $cnf->reset; my $serialized = $cnf->serialize;
new
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 or arrays structure.
Default value is reference to blank hash.
set_conflicts
Set conflicts detection as error.
Default value is 1.
parse
my $struct_hr = $cnf->parse($string_or_array_ref);
Parse string $string_or_array_ref or reference to array $string_or_array_ref and returns structure.
$string_or_array_ref
Returns reference to hash.
reset
$cnf->reset;
Reset content in class (config parameter).
Returns undef.
serialize
my $serialized = $cnf->serialize;
Serialize 'config' parameter hash to output.
Returns string.
# Comment. # blabla # White space. /^\s*$/ # Parameters. # Key must be '[-\w\.:,]+'. # Separator is '='. key=val key2.subkey.subkey=val # Arrays. key3=val1 key3=val2
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_array(): Conflict in '%s'.
use strict; use warnings; use Config::Dot::Array; use Dumpvalue; # Object. my $struct_hr = Config::Dot::Array->new->parse(<<'END'); key1=value1 key2=value2 key2=value3 key3.subkey1=value4 key3.subkey1=value5 END # Dump my $dump = Dumpvalue->new; $dump->dumpValues($struct_hr); # Output: # 0 HASH(0x9970430) # 'key1' => 'value1' # 'key2' => ARRAY(0x9970660) # 0 'value2' # 1 'value3' # 'key3' => HASH(0x9970240) # 'subkey1' => ARRAY(0xa053658) # 0 'value4' # 1 'value5'
use strict; use warnings; use Config::Dot::Array; # Object with data. my $c = Config::Dot::Array->new( 'config' => { 'key1' => { 'subkey1' => 'value1', }, 'key2' => [ 'value2', 'value3', ], }, ); # Serialize. print $c->serialize."\n"; # Output: # key1=subkey1.value1 # key2=value2 # key2=value3
use strict; use warnings; use Config::Dot::Array; use Dumpvalue; # Object. my $struct_hr = Config::Dot::Array->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 key3.subkey1=value4 END # Dump my $dump = Dumpvalue->new; $dump->dumpValues($struct_hr); # Output: # 0 HASH(0x87d05e8) # 'key1' => 'value1' # 'key2' => 'value2' # 'key3' => HASH(0x87e3840) # 'subkey1' => ARRAY(0x87e6f68) # 0 'FOOBAR' # 1 'value4'
Class::Utils, Config::Utils, English, Error::Pure, Readonly.
Module for simple configure file parsing.
Common config utilities.
https://github.com/michal-josef-spacek/Config-Dot-Array
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2011-2023 Michal Josef Špaček
BSD 2-Clause License
0.08
To install Config::Dot::Array, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Dot::Array
CPAN shell
perl -MCPAN -e shell install Config::Dot::Array
For more information on module installation, please visit the detailed CPAN module installation guide.