Skip Menu |

This queue is for tickets about the Config-General CPAN distribution.

Report information
The Basics
Id: 69532
Status: resolved
Priority: 0/
Queue: Config-General

People
Owner: tlinden [...] cpan.org
Requestors: mike [...] mlxvi.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Weird behaviour due to deep references
Date: Sun, 17 Jul 2011 22:07:42 +1200
To: bug-Config-General [...] rt.cpan.org
From: Mike Edmonds <mike [...] mlxvi.org>
I wish to load configuration data from two files The first ParseConfig uses default values in %defaultconfig and puts the result into %finalconfig. The second ParseConfig also uses %defaultconfig for its default values. However, it appears that this second ParseConfig alters the contents of %defaultconfig, and in doing so alters the values in %finalconfig even though %finalconfig is not otherwise assigned changed values. I should imagine the problem is in passing references in the module. Here is the minimal code to demonstrate my problem. Please let me know if you want more info. I am running OpenBSD 4.7, Perl 5.10.1, Config::General 2.42 Mike #! /usr/bin/perl # built-ins use strict ; use warnings ; use Config::General qw (ParseConfig) ; use Data::Dumper ; # the return value my %finalconf = () ; # the defaults updated my %defaultconfig = () ; print "First dump\n" ; print Dumper(\%finalconf) ; # lowest precedence file my $configfile = '2.conf' ; my %config = () ; %config = ParseConfig( -ConfigFile => $configfile, -UseApacheInclude => 1, -AutoTrue =>1, -MergeDuplicateOptions => 1, -MergeDuplicateBlocks => 1, -DefaultConfig => \%defaultconfig, ) ; %finalconf = %config ; print "2nd dump\n" ; print Dumper(\%finalconf) ; # highest precedence file $configfile = '3.conf' ; %config = () ; print "2.5rd dump\n" ; print Dumper(\%config) ; print "3rd dump\n" ; print Dumper(\%finalconf) ; %config = ParseConfig( -ConfigFile => $configfile, -UseApacheInclude => 1, -AutoTrue =>1, -MergeDuplicateOptions => 1, -MergeDuplicateBlocks => 1, -DefaultConfig => \%defaultconfig ) ; print "Second config file\n" ; print Dumper (\%config) ; print "4th dump\n" ; print Dumper(\%finalconf) ; and the config files 2.conf: <section1> value4 This is in the second file and should not appear in the third file at all value5 This is in the second file </section1> 3.conf <section2> # if this is not here then it will not be loaded value1 1 </section2> <section1> value3 This is in the third file value5 This is in the third file and should not appear alongside any 2nd file value </section1>
Comment from duplicate ticket#69533: On Sun Jul 17 07:07:31 2011, mike@mlxvi.org wrote: Show quoted text
> I worked around the issue by using Data::Dumper on the default hash. > > I had a quick look at your code. Maybe you could dereference the > DefaultConfig hashref somewhere in the _proccess sub by dumping and > eval-ing the result before carrying on. > > That way the DefaultConfig hash would come out of the Config::General > ParseConfig function call the same way it went in. > > Just a suggestion. > > > Mike Edmonds
references are required, so I can't (for now) do that.