cvsuser 05/01/30 15:07:44
Modified: App-Options/lib/App Options.pm
Log:
add --version support, fix defaults so that {prefix} variable substitution
works
Revision Changes Path
1.14 +25 -24 p5ee/App-Options/lib/App/Options.pm
Index: Options.pm
===================================================================
RCS file: /cvs/public/p5ee/App-Options/lib/App/Options.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Options.pm 14 Jan 2005 16:28:29 -0000 1.13
+++ Options.pm 30 Jan 2005 23:07:43 -0000 1.14
@@ -1,6 +1,6 @@
#############################################################################
-## $Id: Options.pm,v 1.13 2005/01/14 16:28:29 spadkins Exp $
+## $Id: Options.pm,v 1.14 2005/01/30 23:07:43 spadkins Exp $
#############################################################################
package App::Options;
@@ -761,12 +761,30 @@
}
#################################################################
- # 7. set defaults
+ # 7. establish the definitive (not inferred) $prefix
+ #################################################################
+ if ($values->{prefix}) {
+ if ($prefix eq $values->{prefix}) {
+ print STDERR "7. Definitive prefix found [$prefix] (no
change)\n" if ($debug_options);
+ }
+ else {
+ print STDERR "7. Definitive prefix found [$prefix] =>
[$values->{prefix}]\n" if ($debug_options);
+ $prefix = $values->{prefix};
+ }
+ }
+ else {
+ $values->{prefix} = $prefix;
+ print STDERR "7. prefix Made Definitive [$prefix]\n" if
($debug_options);
+ }
+
+ #################################################################
+ # 8. set defaults
#################################################################
if ($option) {
- @vars = (sort keys %$option);
+ @vars = (defined $init_args{options}) ? @{$init_args{options}} : ();
+ push(@vars, (sort keys %$option));
- print STDERR "7. Set Defaults.\n" if ($debug_options);
+ print STDERR "8. Set Defaults.\n" if ($debug_options);
foreach $var (@vars) {
if (!defined $values->{$var}) {
@@ -786,24 +804,7 @@
}
}
else {
- print STDERR "7. Skipped Defaults (no option defaults defined)\n" if
($debug_options);
- }
-
- #################################################################
- # 8. establish the definitive (not inferred) $prefix
- #################################################################
- if ($values->{prefix}) {
- if ($prefix eq $values->{prefix}) {
- print STDERR "8. Definitive prefix found [$prefix] (no
change)\n" if ($debug_options);
- }
- else {
- print STDERR "8. Definitive prefix found [$prefix] =>
[$values->{prefix}]\n" if ($debug_options);
- $prefix = $values->{prefix};
- }
- }
- else {
- $values->{prefix} = $prefix;
- print STDERR "8. prefix Made Definitive [$prefix]\n" if
($debug_options);
+ print STDERR "8. Skipped Defaults (no option defaults defined)\n" if
($debug_options);
}
#################################################################
@@ -1494,7 +1495,7 @@
assumed to be the value of the $VERSION variable in that package.
i.e. The version of the XYZ::Foo package is $XYZ::Foo::VERSION.)
- prog --version
+ prog --version
Of course, this is all done implicitly in the BEGIN block (during
"use App::Options;"). If your program tried to set
@@ -1512,7 +1513,7 @@
#!/usr/bin/perl
BEGIN {
- $VERSION = do { my @r=(q$Revision: 1.13 $=~/\d+/g); sprintf
"%d."."%02d"x$#r,@r};
+ $VERSION = do { my @r=(q$Revision: 1.14 $=~/\d+/g); sprintf
"%d."."%02d"x$#r,@r};
}
use App::Options;