Subject: | Getargs::Mixed won't accept undef as the value of a parameter |
Sterling,
Thanks for Getargs::Mixed, which I am using and enjoying. I would like to be able to pass `undef` as the value of a parameter. However, Getargs::Mixed sees that as a missing parameter. Test case (Perl 5.26.3, Cygwin x64):
$ perl -E 'use strict;
use warnings;
use Getargs::Mixed;
use Data::Dumper;
my @in = ("-foo", undef);
say Dumper(\@in); # two elements
my (%args) = parameters([qw(foo)], @in);
say Dumper(\%args)'
$VAR1 = [
'-foo',
undef
];
Missing these required arguments: foo at /home/cxw/perl5/lib/perl5/Getargs/Mixed.pm line 235.
Getargs::Mixed::parameters(ARRAY(0x600070618), "-foo", undef) called at -e line 7
I believe this is because https://metacpan.org/source/HANENKAMP/Getargs-Mixed-1.03/Mixed.pm#L234 tests for definedness, not existence. I copied Getargs::Mixed and changed only that line from `grep { !defined ...` to `grep { !exists ...`, with the following result:
$ perl -E 'use strict;
use warnings;
use Arrrgs; # My tweaked test module
use Data::Dumper;
my @in = ("-foo", undef);
say Dumper(\@in); # two elements
my (%args) = parameters([qw(foo)], @in);
say Dumper(\%args)'
$VAR1 = [
'-foo',
undef
];
$VAR1 = {
'foo' => undef
};
I re-ran the Getargs::Mixed test suite with this change, and all tests passed.
Would you be willing to consider adding this change to the distribution? Please let me know if you would like more information, tests, examples, or code. Thank you!
Sincerely,
Chris White (CXW)