Subject: | More pass_through and <> woes |
Hello, I have many programs and packages that use Getopt::Long, thanks for
working on it.
I have started getting user reports of these packages
breaking due to the pass_through with <> change made in or around
Getopt::Long version 2.43.
For now, I have told users to revert to the old version, but obviously that
is temporary until users can upgrade to a version of my scripts that "do
the right thing".
1. The first problem is "Option spec <> cannot be used with pass_through."
was an error. I see that this was just made a warning in 2.44, so thanks
for that.
2. The second problem is even with the warning the behavior has changed so
the old scripts still do not work with 2.44. The older version would pass
the arguments to the <> callback function, while the newer version does not
call the <> callback.
For the example
print "$ver ARGV in: ",join(' ',@ARGV),"\n";
if ($ver eq 'pb') {
Getopt::Long::config ("pass_through");
if (! GetOptions (
"<>" => sub {
print "$ver got <> callback: $_[0]\n"; },
)) {
}
print "$ver ARGV out: ",join(' ',@ARGV),"\n";
Here's an example difference (left is 2.38 right is 2.44 output):
VERSION 2.38 | VERSION 2.44
ARGV in: -I yy | ARGV in: -I yy
| Option spec <> cannot be used with pass_through. FIX IT!
got <> callback: -I |
got <> callback: yy |
ARGV out: |
| ARGV out: -I yy
Could you please add a test to your suite to insure to match the old
behavior after printing the warning?
3. The final problem is I don't see how pass_through and <> are mutually
exclusive (I did read https://rt.cpan.org/Public/Bug/Display.html?id=92462
but unless I am misreading that could have been solved by documentation).
It seems reasonable to want to get "all unknown" arguments and also have my
parameter callback. Specifically consider this example
print "$ver ARGV in: ",join(' ',@ARGV),"\n";
if ($ver eq 'pb') {
Getopt::Long::config ("pass_through");
if (! GetOptions (
"boo" => sub {
print "$ver got boo callback\n"; },
"<>" => sub {
print "$ver got <> callback: $_[0]\n"; },
)) {
}
print "$ver ARGV out: ",join(' ',@ARGV),"\n";
Here's an example difference (left is 2.38 right is 2.44 output):
ARGV in: --unr --boo -I xx | ARGV in: --unr --boo -I xx
| Option spec <> cannot be used with pass_through. FIX IT!
got <> callback: --unr |
got boo callback | got boo callback
got <> callback: -I |
got <> callback: xx |
ARGV out: |
| ARGV out: --unr -I xx
Note with both <> and pass_through the program could determine the ordering
between the unknown parameters (e.g. --unr) and the recognized parameters
(e.g. --boo).
How do I maintain ordering between known and unknown arguments without both
pass_through and <>? Obviously using only pass_through, or only <> will
not work - the former looses ordering, the later will cause unknown option
errors. I would like something that will work with at least 2.38 forward, ideally also working with 2.43.
Thanks!