Config::Neat::Render - Render configs in Config::Neat format
use Config::Neat::Render; my $r = Config::Neat::Render->new(); my $data = { 'foo' => 'Hello, World!', 'bar' => [1, 2, 3], 'baz' => { 'etc' => ['foo bar', 'baz', '', 1] } }; print $r->render($data);
The output will be:
bar 1 2 3 baz { etc `foo bar` baz `` 1 } foo Hello, World!
This module allows you to render Config::Neat-compatible structures from your data (but read below for limitations). See https://github.com/iafan/Config-Neat/blob/master/sample/readme.nconf for the detailed file syntax specification. For parsing, use Config::Neat.
Constructs a new renderer object. $options is a reference to a hash containing rendering options' overrides (see the RENDERING OPTIONS section below).
Renders $data into a string and returns it. $options is a reference to a hash containing rendering options' overrides (see the RENDERING OPTIONS section below).
A number of spaces to indent each nested block contents with.
Default value: 4
4
A number of spaces between a key and and a value.
A suggested maximum width of each line in a multiline string or array.
Default value: 60
60
If true, put the opening brace under the key name, not on the same line
Default value: 1 (true)
1
If true, surrond blocks with empty lines for better readability.
If true, align all values in the configuration file (otherwise the values are aligned only within current block).
Note that hashes in Perl do not guarantee the correct order, so blocks may have individual parameters shuffled randomly. Set this option to a true value if you want to sort keys alphabetically, or to a reference to an array holding an ordered list of key names
Default value: undef (false)
undef
Example:
my $data = { 'bar' => [1, 2, 3], 'baz' => { 'etc' => ['foo bar', 'baz', '', 1] } 'foo' => 'Hello, World!', }; my @order = qw(foo bar baz); print $r->render($data, {sort => \@order});
foo Hello, World! bar 1 2 3 baz { etc `foo bar` baz `` 1 }
A string representation of the value to emit for undefined values
Default value: 'NO'
'NO'
Do not use Config::Neat::Render in conjunction with Config::Neat for arbitrary data serialization/desrialization. JSON and YAML will work better for this kind of task.
Why? Because Config::Neat was primarily designed to allow easier configuration file authoring and reading, and uses relaxed syntax where strings are treated like space-separated arrays (and vice versa), and where there's no strict definition for boolean types, no null values, etc.
It's the developer's responsibility to treat any given parameter as a boolean, or string, or an array. This means that once you serialize your string into Config::Neat format and parse it back, it will be converted to an array, and you will need to use `->as_string` method to get the value as string.
In other words, when doing this:
my $c = Config::Neat->new(); my $r = Config::Neat::Render->new(); my $parsed_data = $c->parse($r->render($arbitrary_data));
$parsed_data will almost always be different from $arbitrary_data.
However, doing this immediately after:
my $parsed_data_2 = $c->parse($r->render($parsed_data));
Should produce the same data structure again.
Copyright (C) 2012-2015 Igor Afanasyev <igor.afanasyev@gmail.com>
https://github.com/iafan/Config-Neat
To install Config::Neat, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Neat
CPAN shell
perl -MCPAN -e shell install Config::Neat
For more information on module installation, please visit the detailed CPAN module installation guide.