Skip Menu |

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

Report information
The Basics
Id: 111158
Status: new
Priority: 0/
Queue: Getopt-ArgParse

People
Owner: Nobody in particular
Requestors: Mark.Bannister [...] morganstanley.com
Cc:
AdminCc:

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



Subject: Getopt::ArgParse copy_args() causing undefined value error in Getopt/ArgParse/Parser.pm line 1184
Date: Wed, 13 Jan 2016 17:39:39 +0000
To: "'bug-Getopt-ArgParse [...] rt.cpan.org'" <bug-Getopt-ArgParse [...] rt.cpan.org>
From: "Bannister, Mark" <Mark.Bannister [...] morganstanley.com>
I've found a bug with this library, specifically to do with the copy_args() method: use Getopt::ArgParse; my $ap = Getopt::ArgParse->new_parser( prog => 'testcmd', error_prefix => 'testcmd: ', sortby => 'name', description => 'Test Getopt::ArgParse.'); $ap->add_arg('--log', type => 'Scalar', help => 'log file'); my $ap2 = Getopt::ArgParse->new_parser( prog => 'testcopy', error_prefix => 'testcopy: ', sortby => 'name', description => 'Test copying Getopt::ArgParse.'); $ap2->add_arg('--logdir', type => 'Scalar', help => 'log dir'); $ap2->copy_args($ap); $ap2->parse_args(); When executed the result is: Can't use an undefined value as an ARRAY reference at //ms/dist/perl5/PROJ/Getopt-ArgParse/1.0.6/lib/perl5/Getopt/ArgParse/Parser.pm line 1184. On investigation and experimentation, I've discovered that this is because copy_args() copies the default '--help' argument so there are two occurrences of this argument in the resulting '-pristine_add_arguments' hash. One fix would be for copy_args() to avoid duplicating this argument. If I replace the '$ap2->copy_args($ap)' line above with the following: my @copyargs; for my $a (@{$ap->{-pristine_add_arguments}}) { push @copyargs, $a if $a->[0] ne '--help'; } $ap2->add_args(@copyargs); The result is as expected: usage: testcopy [--help|-h] [--log] [--logdir] Test copying Getopt::ArgParse. optional named arguments: --help, -h ? show this help message and exit --log LOG ? log file --logdir LOGDIR ? log dir Would it be possible to add a fix similar to the above in a new version of the library on CPAN? Best regards, Mark. Show quoted text
________________________________ NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies; do not disclose, use or act upon the information; and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.
Subject: RE: [rt.cpan.org #111158] Getopt::ArgParse copy_args() causing undefined value error in Getopt/ArgParse/Parser.pm line 1184
Date: Wed, 13 Jan 2016 18:08:35 +0000
To: "'bug-Getopt-ArgParse [...] rt.cpan.org'" <bug-Getopt-ArgParse [...] rt.cpan.org>
From: "Bannister, Mark" <Mark.Bannister [...] morganstanley.com>
I forgot to mention in the bug report that this was encountered with Getopt-ArgParse 1.0.6 and occurs on all Perl versions (I’ve tested 5.10, 5.14 and 5.20). Here is a patch, inspired by a similar code block in the copy_parsers() method: --8<--------------------------- --- Getopt/ArgParse/Parser.pm.orig 2016-01-13 17:56:11.698892000 +0000 +++ Getopt/ArgParse/Parser.pm 2016-01-13 18:07:37.272863000 +0000 @@ -174,7 +174,11 @@ _croak 'Parent is missing' unless $parent; _check_parent($parent); - $self->add_arguments( @{ $parent->{-pristine_add_arguments} } ); + for my $args (@{$parent->{-pristine_add_parser}}) { + my $flag = $args->[0]; + next if $flag eq '--help'; + $self->add_argument( @$args ); + } } sub copy_parsers { --8<--------------------------- Best regards, Mark. -------------------------------------------------------------------------------- NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies; do not disclose, use or act upon the information; and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.
Subject: RE: [rt.cpan.org #111158] Getopt::ArgParse copy_args() causing undefined value error in Getopt/ArgParse/Parser.pm line 1184
Date: Wed, 13 Jan 2016 18:17:52 +0000
To: "'bug-Getopt-ArgParse [...] rt.cpan.org'" <bug-Getopt-ArgParse [...] rt.cpan.org>
From: "Bannister, Mark" <Mark.Bannister [...] morganstanley.com>
Apologies, bad diff. Try this instead: --8<--------------------------- --- Getopt/ArgParse/Parser.pm.orig 2016-01-13 17:56:11.698892000 +0000 +++ Getopt/ArgParse/Parser.pm 2016-01-13 18:16:40.242813000 +0000 @@ -174,7 +174,11 @@ _croak 'Parent is missing' unless $parent; _check_parent($parent); - $self->add_arguments( @{ $parent->{-pristine_add_arguments} } ); + for my $args (@{$parent->{-pristine_add_arguments}}) { + my $flag = $args->[0]; + next if $flag eq '--help'; + $self->add_argument( @$args ); + } } sub copy_parsers { --8<--------------------------- Best regards, Mark. -------------------------------------------------------------------------------- NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies; do not disclose, use or act upon the information; and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.