Skip Menu |

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

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

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

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



Subject: Configuration to be passed with call
Getopt::Long provides several configuration options which can be set with its Configure() routine. But this is awkward to use in a library. I want to set some configuration options in my routine but not have them affect any GetOptions calls that happen after my routine finishes. While I could call Configure() again to set the options back, I don't actually know what they were before. It would be more usable for configuration options to be passed in directly to the GetOptions call, perhaps by a hashref passed as the first argument. Then GetOptions({ pass_through => 1 }, 'foo' => \$foo); would set the pass_through flag just for this call (but the current configured settings otherwise). Where you want to ignore any prior Configure() calls and use a known set of options, the existing 'default' option could be used: GetOptions({ default => 1, pass_through => 1}, ...) will set pass_through but use the default config otherwise. The implementation will have to be a little bit careful since hash keys are unordered, so it should look for 'default' first.
If you use Getopt::Long the object oriented way the individual instances maintain their own configurations and do not get in the way of each other, and non-OO calls. use Getopt::Long; $p = Getopt::Long::Parser->new; $p->configure(...); if ($p->getoptions(...)) ...
Ah, thanks, that should do it. Perhaps a note in the docs, to say Getopt::Long can be configured by calling subroutine Getopt::Long::Configure(), or in object-oriented usage, the method configure().