Skip Menu |

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

Report information
The Basics
Id: 17497
Status: resolved
Priority: 0/
Queue: Config-Std

People
Owner: Nobody in particular
Requestors: dwheeler [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.0.2
Fixed in: v0.0.3



Subject: Eliminate Warnings For Undefined Values
Date: Sun, 5 Feb 2006 19:14:15 -0800
To: bug-config-std [...] rt.cpan.org
From: David Wheeler <dwheeler [...] cpan.org>
If a setting that I'm writing to my config file is set to a value of 'undef', I get warnings: Use of uninitialized value in substitution (s///) at /usr/local/ lib/perl5/site_perl/5.8.7/Config/Std.pm line 78. The attached patch adds a test for this warning and fixes it. It adds a dependency on Test::NoWarnings, but I think that it's worth it. Best, David

Message body is not shown because sender requested not to inline it.

On Sun Feb 05 22:16:10 2006, DWHEELER wrote: Show quoted text
> The attached patch adds a test for this warning and fixes it. It adds > a dependency on Test::NoWarnings, but I think that it's worth it.
Bah! Sorry, new patch that doesn't add test.cfg attachd. Best, David
diff -Naur Config-Std-0.0.2.old/Build.PL Config-Std-0.0.2/Build.PL --- Config-Std-0.0.2.old/Build.PL 2005-05-21 22:59:35.000000000 -0700 +++ Config-Std-0.0.2/Build.PL 2006-02-05 19:12:46.000000000 -0800 @@ -11,6 +11,7 @@ 'Test::More' => 0, 'Class::Std' => 0, 'version' => 0, + 'Test::NoWarnings' => 0, }, add_to_cleanup => [ 'Config-Std-*' ], ); diff -Naur Config-Std-0.0.2.old/lib/Config/Std.pm Config-Std-0.0.2/lib/Config/Std.pm --- Config-Std-0.0.2.old/lib/Config/Std.pm 2005-05-25 15:30:51.000000000 -0700 +++ Config-Std-0.0.2/lib/Config/Std.pm 2006-02-05 19:12:15.000000000 -0800 @@ -74,7 +74,8 @@ $sep = $SEPARATOR{$sep || $def_sep}; - my @vals = $val_type eq 'ARRAY' ? @{$val} : $val; + my @vals = map { defined() ? $_ : '' } + $val_type eq 'ARRAY' ? @{$val} : $val; s/ (?!\Z) \n /\n$keyspace$sep/gxms for @vals; $serialization .= $comm || q{}; diff -Naur Config-Std-0.0.2.old/t/00write.t Config-Std-0.0.2/t/00write.t --- Config-Std-0.0.2.old/t/00write.t 2005-05-19 03:04:26.000000000 -0700 +++ Config-Std-0.0.2/t/00write.t 2006-02-05 19:12:15.000000000 -0800 @@ -1,5 +1,8 @@ +#!/usr/bin/perl -w use Config::Std; +use strict; use Test::More 'no_plan'; +use Test::NoWarnings; my $output_file = 'test.cfg'; @@ -15,6 +18,7 @@ 'Named' => { 'hi there' => q{What's your name???}, 'list' => [qw(a list of values), 'all different'], + 'undef' => undef }, # Complex named section... @@ -32,7 +36,7 @@ ok my $orig_config = do{ local $/; <DATA> } => 'DATA loaded'; -is $orig_config, $config => 'Content correct'; +is $config, $orig_config => 'Content correct'; __DATA__ @@ -56,6 +60,8 @@ hi there: What's your name??? +undef: + list: a list: list list: of
Subject: Re: [rt.cpan.org #17497] Eliminate Warnings For Undefined Values
Date: Thu, 9 Feb 2006 15:25:29 +1100
To: bug-Config-Std [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
David Wheeler wrote: Show quoted text
> If a setting that I'm writing to my config file is set to a value of > 'undef', I get warnings
Given that you're serializing the undefined values in such a way that they will be changed (to empty strings) when read back in, it's arguable that a warning is necessary (though I will concede that the warning ought to be clearer, and reported from the caller's POV, rather than the module's). However, I think it would be more "faithful" if the module simply removed any entries with undefined values. That way, when the config data was reloaded, the corresponding entry, when queried, would correctly be autoviviified to undef. Thanks for pointing out the problem, David. Damian
Subject: Re: [rt.cpan.org #17497] Eliminate Warnings For Undefined Values
Date: Wed, 8 Feb 2006 20:32:17 -0800
To: bug-Config-Std [...] rt.cpan.org
From: David Wheeler <dwheeler [...] cpan.org>
On Feb 8, 2006, at 20:26, damian@conway.org via RT wrote: Show quoted text
> Given that you're serializing the undefined values in such a way that > they will be changed (to empty strings) when read back in, it's > arguable that a warning is necessary (though I will concede that the > warning ought to be clearer, and reported from the caller's POV, > rather than the module's).
Yes, that's what I was starting to think, actually. I want to know when something is unexpectedly undefined. Then I can fix it. Show quoted text
> However, I think it would be more "faithful" if the module simply > removed any entries with undefined values. That way, when the config > data was reloaded, the corresponding entry, when queried, would > correctly be autoviviified to undef.
Yes, but then you can't iterate over it using keys or each (which is how I'm using the config hash). Best, David
Subject: Re: [rt.cpan.org #17497] Eliminate Warnings For Undefined Values
Date: Thu, 9 Feb 2006 15:40:09 +1100
To: bug-Config-Std [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
> Yes, that's what I was starting to think, actually. I want to know > when something is unexpectedly undefined. Then I can fix it.
Okay, so that argues that it ought to be an exception, not a warning. Damian
Subject: Re: [rt.cpan.org #17497] Eliminate Warnings For Undefined Values
Date: Wed, 8 Feb 2006 22:04:09 -0800
To: bug-Config-Std [...] rt.cpan.org
From: David Wheeler <dwheeler [...] cpan.org>
On Feb 8, 2006, at 20:40, damian@conway.org via RT wrote: Show quoted text
> Okay, so that argues that it ought to be an exception, not a warning.
Yes, I think so, though I wouldn't mind a configuration setting of some kind to change the behavior. But I don't know how much you want to get into that. Best, David