Subject: | changes for consideration |
The attached patch includes two changes to the module i would find useful. In reverse order:
1) Moves the code that is run for an unrecognized option out into its own subroutine. This allows me to override the default action with something else
2) Provides for further processing of the command line after the appropriate code has been run for an option, by not exiting the loop if a true value is returned from the option code. this allows for chaining of commands
eg program command1 option1 option2 command2 command3 option1
where the options are processed by the code provided for each command
Jody Belka
--- Auto.pm 2003-01-03 15:27:48.000000000 +0000
+++ Auto.pm.new 2003-08-01 18:26:28.000000000 +0100
@@ -137,8 +137,7 @@
if (grep { /^--version|-V$/ } @ARGV) { version(); exit 0; }
while (my $foo = shift @ARGV) {
if (exists $options{$foo}) {
- $options{$foo}{code}->(@ARGV);
- exit;
+ exit if !$options{$foo}{code}->(@ARGV);
} else {
if (_type($foo) ne $type and _type($foo) ne "bare") {
if (_type($foo) eq "short") {
@@ -150,14 +149,20 @@
}
} else {
# Don't know this.
- print STDERR "Unrecognised option $foo\n";
- helpme();
+ unrecognized($foo);
}
}
}
if (exists &main::default) { main::default() }
}
+sub unrecognized {
+ my $command = shift;
+
+ print STDERR "Unrecognised option $command\n";
+ helpme();
+}
+
package Getopt::Auto::PodExtract;
use base 'Pod::Parser';