Skip Menu |

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

Report information
The Basics
Id: 50486
Status: stalled
Priority: 0/
Queue: Config-General

People
Owner: Nobody in particular
Requestors: marcoep [...] gmail.com
Cc:
AdminCc:

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



Subject: Variable interpolation doesn't work for "Include" statements
Hi there, It looks like that variable interpolation doesn't work in "include" statements (or I'm missing something). Indeed, the following use Config::General; my @config_lines = ( 'FOO = barrc', '<<include $FOO>>' ); my $conf = new Config::General( -String => \@config_lines, -InterPolateVars => 1 ); produces: Config::General The file "$FOO" does not exist! at /tmp/configen-test line 9 Best regards, Marco
It's not possible because includes happens in an earlier stage (before variable interpolation).
From: marcoep [...] gmail.com
Le Mer 31 Mar 2010 07:24:29, TLINDEN a écrit : Show quoted text
> It's not possible because includes happens in an earlier stage (before > variable interpolation).
Ouch. OK, but, please, make this clear in the documentation. Cheers, Marco
From: fbicknel [...] nc.rr.com
On Wed Dec 15 04:54:46 2010, marcoep@gmail.com wrote: Show quoted text
> Le Mer 31 Mar 2010 07:24:29, TLINDEN a écrit :
> > It's not possible because includes happens in an earlier stage (before > > variable interpolation).
> > Ouch. OK, but, please, make this clear in the documentation. > Cheers, > Marco
I would like to add this similar odd behavior: If you use -DefaultConfig => ..., this config isn't so much a default as one that's inserted before yours is read in. Thus, if you define: -DefaultConfig => { FOO => 'bar' }, Then you mention this in your config file: FOO = baz SLOO = $FOO (with -InterPolateVars on, of course), the expected value of SLOO = baz is NOT produced, rather you get SLOO = 'bar'.... and as an added obfuscation benefit, the value of FOO turns out to be [ qw (bar baz) ]. The final nail: if you want to use interpolation, you MUST have the variable defined IN THE CURRENT CONFIG, as there doesn't seem to be any way to include any sort of default, even leaving it out completely. (Config::General blows up if it finds a $FOO with no corresponding FOO=... defined.) If -DefaultConfig behaved in a more reasonable manner, I would expect it to use those values only if they're not defined by the user's config file. Thus, I would expect it to interpolate variables based on either the user-defined value in the config file or in the default config, respectively, whichever is defined first. And as Marco is requesting, any INCLUDES should be sucked in first before interpolation takes place.
From: fbicknel [...] nc.rr.com
On Thu May 12 14:27:46 2011, fbicknel wrote: Show quoted text
> The final nail: if you want to use interpolation, you MUST have the > variable defined IN THE CURRENT CONFIG, as there doesn't seem to be any > way to include any sort of default, even leaving it out completely. > (Config::General blows up if it finds a $FOO with no corresponding > FOO=... defined.)
My apologies: you can turn off -StrictVars to allow $FOO to remain undefined. Which brings up a better thought: what if you could delay interpolation to the time when you access the item? Example: BAZ = $FOO ... include foodef (in foodef) FOO = Green - or - $self->value (FOO => 'Green'); ... This results in BAZ = $FOO, but when you later access BAZ: $foo = $self->value ('BAZ'); the value returned (to $foo) is 'Green', since FOO at that time has the value 'Green'. Better, maybe? Some may prefer a new parameter such as -DeferInterpolation to enable such a feature. Of course, those who like to use ->getall at the start will miss out on some nice parts of this, especially if you set values later.
From: fbicknel [...] nc.rr.com
On Thu May 12 17:34:17 2011, fbicknel wrote: Show quoted text
> Which brings up a better thought: what if you could delay interpolation > to the time when you access the item?
Whoa - I actually got this to work using the 2.50 code with a rather simple few-lines change to Extended.pm (in AUTOLOAD and value). If it is as easy to fix for hash values as well, I'll shoot you a diff.
On Fri May 13 15:07:07 2011, fbicknel wrote: Show quoted text
> On Thu May 12 17:34:17 2011, fbicknel wrote:
> > Which brings up a better thought: what if you could delay interpolation > > to the time when you access the item?
> > Whoa - I actually got this to work using the 2.50 code with a rather > simple few-lines change to Extended.pm (in AUTOLOAD and value). > > If it is as easy to fix for hash values as well, I'll shoot you a diff.
Do you have a diff already?