There has been some discussion this month about CPAN and github and how me might use them better:
Coincidentally, I ran into a bug this week that seems related. Namely, that Config::Simple steps on the $_ variable. That is, if we have something like this
$_ = 'happy'; my $cs = Config::Simple->new('foo.ini'); is $_, 'happy';
the test fails
$ ./useConfigSimple.pl ✖ L16: is $_, 'happy'; # Failed test ' L16: is $_, 'happy';' # at ./useConfigSimple.pl line 16. # got: '[Counter]' # expected: 'happy'
In other words, we are no longer happy. What is '[Counter]'? That's some junk from the config file we read in
$ cat foo.ini [Counter] font = Helvetica 36 bold padx = 10 pady = 50 counter = 4 start = 0
To fix it, we have to localize the topic before calling Config::Simple. Changing the code to
$_ = 'happy'; my $cs = do {local $_; Config::Simple->new('foo.ini')}; is $_, 'happy';
gives
$ ./useConfigSimple.pl ✓ L16: is $_, 'happy';
So, we are happy again!
Well, that seemed pretty easy to fix, but in reality is was difficult to track down. Config::Simple was being called conditionally by a subroutine inside a map, so sometimes there was junk in the result and sometimes there wasn't.
It turns out this bug was reported a long time ago. Curiously, searching for Config::Simple on metacpan leads to version 4.58, but searching on search.cpan.org leads to version 4.59. That's no big deal because both have the bug as well as the link to the bug report. And that's what we really need to find, since the thread there reveals that Joe Atzberger patched the bug almost a year ago and there's a version 4.60 on github. It looks like he offered to adopt the one on CPAN, but that didn't happen.
Thankfully, the latest version of cpanm can install directly from github!
$ cpanm git://github.com/atz/Config-Simple.git Cloning git://github.com/atz/Config-Simple.git ... OK --> Working on git://github.com/atz/Config-Simple.git Configuring Config-Simple-4.60 ... OK Building and testing Config-Simple-4.60 ... OK Successfully installed Config-Simple-4.60 cannot remove path when cwd is /tmp/it6rDijaB2 for /tmp/it6rDijaB2: at /home/tim/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.3/File/Temp.pm line 2445. 1 distribution installed
Supergood! (No, I don't understand why I'm getting that warning from File::Temp).
Thanks to atz for fixing Config::Simple and thanks to miyagawa for cpanm!
the new features of cpanm are great, but we should find a way to release the new version to CPAN so people will know about it. Github has the fix, but most people will never know!
Also the File::Temp warning surely comes from being in the directory at the end of the script. File::Temp tries to remove the temporary folder, but it can't because it is the current working directory. Adding `my $orig = getcwd;` near the top, and `chdir $orig;` near the end will fix the warning (and more importantly allow proper removal of the temporary directory).
Posted by: Joel Berger | 03/16/2013 at 03:05 PM
I agree. That's why I think this is related to the other discussions about CPAN and not just a post about a bug in Config::Simple. Here is a case where it's not experimental code on github and polished code on CPAN, but tarnished code on CPAN and a corrected version on github. We seem to have someone willing and able to correct the bug, but we are unable to correct the bug on CPAN without cooperation from the maintainer.
I also agree about the File::Temp warning. Leaving the temporary directory upon successful install seems to both silence the error and remove the directory.
Posted by: oylenshpeegul | 03/17/2013 at 06:33 AM
I asked about the s.c.o vs metacpan inconsistency on #metacpan IRC channel...
16:36 < rwstauner> ranguard: latest according to 02packages is 4.58
16:37 < rwstauner> which is what metacpan shows
16:37 < rwstauner> i don't know why 4.59 isn't indexed
16:37 < rwstauner> but metacpan matches my 02packages
16:51 < BinGOs> there is no .readme nor .meta for Config-Simple-4.59
16:52 < BinGOs> which is indicative of PAUSE indexer not indexing
Just for anyone interested
Posted by: Ranguard | 03/18/2013 at 01:34 PM