Skip Menu |

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

Report information
The Basics
Id: 104842
Status: resolved
Priority: 0/
Queue: Getopt-Long

People
Owner: jv [...] cpan.org
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.45
Fixed in: 2.46



Subject: OO interface interferes with later functional calls
Thanks for your earlier response where you suggested using the OO interface to Getopt::Long. However, it appears that doing so breaks later calls to the procedural GetOptions() interface. For example: package P; use 5.018; use Getopt::Long; my $opt_foo; sub f { say "args before OO call: @ARGV"; my $p = new Getopt::Long::Parser; $p->configure('pass_through'); $p->getoptions(foo => \$opt_foo); say "args after OO call: @ARGV"; } package main; use 5.018; use Getopt::Long; P::f; say "args before procedural call: @ARGV"; our ($opt_bar); GetOptions('bar'); say "args after procedural call: @ARGV"; Save this as 'test' and run 'perl test --foo --bar'. For me this prints args before OO call: --foo --bar args after OO call: --bar args before procedural call: --bar args after procedural call: --bar option given? So although the procedural GetOptions() call is taking '--bar' off @ARGV, it fails to set the global $opt_bar as would be expected. Somehow this seems to depend on the earlier OO call being in a separate package.
Sorry the last line of the test program got chopped off, it should be say "--bar option given? $opt_bar";
Good catch! Can you try the attached fix?
Subject: gol.patch
*** Getopt/Long.pm~ 2015-02-23 20:29:11.049237804 +0100 --- Getopt/Long.pm 2015-06-01 18:56:00.558275055 +0200 *************** *** 1312,1324 **** my (@options) = @_; my $prevconfig = ! [ $error, $debug, $major_version, $minor_version, $autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, $gnu_compat, $passthrough, $genprefix, $auto_version, $auto_help, $longprefix, $bundling_values ]; if ( ref($options[0]) eq 'ARRAY' ) { ! ( $error, $debug, $major_version, $minor_version, $autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, $gnu_compat, $passthrough, $genprefix, $auto_version, $auto_help, $longprefix, $bundling_values ) = @{shift(@options)}; --- 1312,1324 ---- my (@options) = @_; my $prevconfig = ! [ $error, $debug, $major_version, $minor_version, $caller, $autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, $gnu_compat, $passthrough, $genprefix, $auto_version, $auto_help, $longprefix, $bundling_values ]; if ( ref($options[0]) eq 'ARRAY' ) { ! ( $error, $debug, $major_version, $minor_version, $caller, $autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, $gnu_compat, $passthrough, $genprefix, $auto_version, $auto_help, $longprefix, $bundling_values ) = @{shift(@options)};
Thanks, that seems to take care of it.