Subject: | Mixing blocks and single-value items |
I'm not sure if I should refer to version 2.34 (which is $VERSION) or 2.36 (which is the
tarfilenumber). Regardless... consider this config file:
<show one>
color green
linetype dashed
</show>
<show two>
color red
</show>
show three
show four
When I parse it using the following simple code:
#!/usr/bin/perl
use Data::Dumper;
use Config::General qw(ParseConfig);
%cfg = ParseConfig(-ConfigFile => '/tmp/foo');
print Data::Dumper::Dumper \%cfg;
I see what I expect to see:
$VAR1 = {
'show' => [
{
'one' => {
'color' => 'green',
'linetype' => 'dashed'
},
'two' => {
'color' => 'red',
}
},
'three',
'four'
]
};
However, if I swap the order of a show item with a show block, so that my config file reads
like this instead:
show three
<show one>
color green
linetype dashed
</show>
<show two>
color red
</show>
show four
Then I get the following error:
Can't use string ("three") as a HASH ref while "strict refs" in use at /usr/local/lib/perl5/
site_perl/5.8.5/Config/General.pm line 803.
Note that setting -ApacheCompatible makes no difference. If I change the config thusly (so
that there are 2 items before any block):
show three
show four
<show one>
color green
linetype dashed
</show>
<show two>
color red
</show>
Then I get a different (but related) error:
Can't coerce array into hash at /usr/local/lib/perl5/site_perl/5.8.5/Config/General.pm
line 803.
And just to be complete, when I do this:
<show one>
color green
linetype dashed
</show>
show three
<show two>
color red
</show>
show four
I get yet another error, but at least Config::General recognizes a problem:
Pseudo-hashes are deprecated at /usr/local/lib/perl5/site_perl/5.8.5/Config/General.pm
line 803.
Cannot add named block <show two> to hash! Block <show> occurs more than once.
Turn on -MergeDuplicateBlocks or make sure <show> occurs only once in the config.
at tx line 4
I understand why it is happening, but don't know how best to fix it (I could stumble my way
through, but I suspect you'd do something neater, knowing the code better.
I believe that the correct behavior is to always have Config::General produce data similar to
that seen in the first example (rather than making all of them illegal with an error message).
If you are curious, I use your module at http://www.klein.com/thermd/, and my
workaround has been to create both a "show name" item and a "<show+ name>"
block, which clunky but works...
This is on FreeBSD 5.3, perl 5.8.5