Subject: | Bug in interpolation after 3-tiered subsections |
Looks like there is a bug in parsing config files with more than two-levels of sub sections in version 2.27 / 2.04. Note the following sample config:
HOME=/home/user
<child1>
<child2>
<child3>
foobar=1
</child3>
</child2>
</child1>
<setdir>
dir=$HOME/etc
</setdir>
It will error out on $HOME being an undefined variable. I have attached a patch which I think fixes this. I converted upperkey to a stack of upperkeys.
fwiw, without the patch, lastkey is child1 rather than " " inside the <setdir> section.
I also made a minor change to the undefined variable error message that makes it a little easier to identify the line an error is occuring on (e.g. if you have a file that uses the same $var numerous times). I had wanted that message to also print out the config file line number that happened on, but it doesn't look like that info is available/saved while loading the configfile into memory.
Cheers,
Brian Dowling
diff -u -r Config/General/Interpolated.pm /usr/lib/perl5/site_perl/5.8.3/Config/General/Interpolated.pm
--- Config/General/Interpolated.pm 2005-01-24 12:00:18.059489088 -0500
+++ /usr/lib/perl5/site_perl/5.8.3/Config/General/Interpolated.pm 2005-01-24 10:32:21.107707696 -0500
@@ -81,7 +81,7 @@
}
else {
if ($this->{StrictVars}) {
- croak "Use of uninitialized variable (\$$var) while loading config entry: $key = $value\n";
+ croak "Use of uninitialized variable \$" . $var . "\n";
}
else {
# be cool
@@ -106,14 +106,14 @@
my ($this, $config) = @_;
$this->{level} = 1;
- $this->{upperkeys} = [];
+ $this->{upperkey} = "";
$this->{lastkey} = "";
$this->{prevkey} = " ";
$config = $this->_var_hash_stacker($config);
$this->{level} = 1;
- $this->{upperkeys} = [];
+ $this->{upperkey} = "";
$this->{lastkey} = "";
$this->{prevkey} = " ";
diff -u -r Config/General.pm /usr/lib/perl5/site_perl/5.8.3/Config/General.pm
--- Config/General.pm 2005-01-24 11:59:38.047571824 -0500
+++ /usr/lib/perl5/site_perl/5.8.3/Config/General.pm 2005-01-24 11:42:19.867399200 -0500
@@ -77,7 +77,7 @@
Tie => "", # could be set to a perl module for tie'ing new hashes
parsed => 0, # internal state stuff for variable interpolation
- upperkeys => [],
+ upperkey => "",
lastkey => "",
prevkey => " ",
};
@@ -731,7 +731,7 @@
sub _savelast {
my($this, $key) = @_;
- push(@{$this->{upperkeys}}, $this->{lastkey});
+ $this->{upperkey} = $this->{lastkey};
$this->{lastkey} = $this->{prevkey};
$this->{prevkey} = $key;
}
@@ -739,7 +739,7 @@
sub _backlast {
my($this, $key) = @_;
$this->{prevkey} = $this->{lastkey};
- $this->{lastkey} = pop(@{$this->{upperkeys}});
+ $this->{lastkey} = $this->{upperkey};
}
sub _parse_value {