Skip Menu |

This queue is for tickets about the Getopt-Simple CPAN distribution.

Report information
The Basics
Id: 33299
Status: resolved
Priority: 0/
Queue: Getopt-Simple

People
Owner: Nobody in particular
Requestors: jay-perl [...] 3pound.com
Cc:
AdminCc:

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



Subject: Integer options, zero is ignored in favor of default
# echo 'use Data::Dumper; use Getopt::Simple; $opt = new Getopt::Simple; $opt->getOptions({"purge" => { type=>"=i", default => 1, order => 1 }}, "usage..", 1,1); $opt->dumpOptions(); die Dumper($opt->{switch})' > /tmp/zero.pl # perl /tmp/zero.pl -p 4321 Option Value -purge 4321 $VAR1 = { 'purge' => 4321 }; # perl /tmp/zero.pl -p 0 Option Value -purge 1 $VAR1 = { 'purge' => 1 }; # perl /tmp/zero.pl -p '0' Option Value -purge 1 $VAR1 = { 'purge' => 1 }; # echo 'use Data::Dumper; use Getopt::Long; my $opts = {}; GetOptions("purge=i" => \$opts->{purge}); die Dumper($opts);' > /tmp/zero_long.pl # perl /tmp/zero_long.pl -p 5678 $VAR1 = { 'purge' => 5678 }; # perl /tmp/zero_long.pl -p 0 $VAR1 = { 'purge' => 0 }; # perl /tmp/zero_long.pl -p '0' $VAR1 = { 'purge' => 0 }; # perl -le 'use Data::Dumper; foreach (qw(Getopt::Simple Getopt::Long)) { print "$_"; eval "use $_;"; print eval "\$".$_."::VERSION;"; }' Getopt::Simple 1.48 Getopt::Long 2.35
Subject: accept_zero_as_integer.patch
--- Simple.pm.orig 2008-02-16 06:37:58.000000000 -0600 +++ Simple.pm 2008-02-16 06:38:06.000000000 -0600 @@ -114,6 +114,6 @@ } else { - $$self{'switch'}{$_} = $$self{'default'}{$_}{'default'} if (! $$self{'switch'}{$_}); + $$self{'switch'}{$_} = $$self{'default'}{$_}{'default'} unless (defined $$self{'switch'}{$_}); } }
Patch corrected to apply to 2 lines, and applied. V 1.49 uploaded to CPAN.
Patched as suggested by JJARVINEN. $many x $thanx;