Author: spadkins
Date: Mon Aug 23 10:02:30 2010
New Revision: 14334
Modified:
p5ee/trunk/App-Options/lib/App/Options.pm
Log:
support secure attributes (passwords) to hide them during --help. fix bug when
% is embedded in the description
Modified: p5ee/trunk/App-Options/lib/App/Options.pm
==============================================================================
--- p5ee/trunk/App-Options/lib/App/Options.pm (original)
+++ p5ee/trunk/App-Options/lib/App/Options.pm Mon Aug 23 10:02:30 2010
@@ -401,12 +401,15 @@
my ($var, $value, @vars, $option);
my $init_args = $self->{init_args};
$option = $init_args->{option};
+ my (%secure_options, %files_with_secure_options, %option_source);
if ($option) {
croak "App::Options->read_options(): 'option' arg must be a hash
reference"
if (ref($option) ne "HASH");
my (@args, $hash, $arg);
+ # Convert archaic forms where everything is packed in a scalar, to the
newer,
+ # more verbose form where attributes of an option are in a hashref.
foreach $var (keys %$option) {
$value = $option->{$var};
if (ref($value) eq "") {
@@ -425,6 +428,19 @@
}
}
}
+ else {
+ $hash = $value;
+ }
+ if ($hash->{secure} || $var =~ /pass(word|wd)?$/) {
+ $secure_options{$var} = $hash->{secure} || 1;
+ }
+ }
+ }
+ if ($init_args->{options}) {
+ foreach $var (@{$init_args->{options}}) {
+ if ($var =~ /pass(word|wd)?$/ && ! defined $secure_options{$var}) {
+ $secure_options{$var} = 1;
+ }
}
}
@@ -462,6 +478,7 @@
$value = ($2 eq "") ? 1 : $3;
push(@$options, shift @ARGV);
$values->{$var} = $value;
+ $option_source{$var} = "CMDLINE";
}
if ($#ARGV >= 0 && $ARGV[0] eq "--") {
shift @ARGV;
@@ -667,6 +684,7 @@
if ($debug_options >= 3);
}
$values->{$var} = $value; # save all in %App::options
+ $option_source{$var} = "ENV";
}
}
}
@@ -677,6 +695,7 @@
$var =~ s/^app_//;
if (! defined $values->{$var}) {
$values->{$var} = $ENV{$env_var};
+ $option_source{$var} = "ENV";
print STDERR " Env Var [$var] = [$value] from
[$env_var] (assumed).\n"
if ($debug_options >= 3);
}
@@ -725,6 +744,7 @@
if ($debug_options >= 4);
}
$values->{$var} = $value; # save all in %App::options
+ $option_source{$var} = "DEFAULT";
print STDERR " Default Var [$var] = [$value]\n" if
($debug_options >= 3);
}
}
@@ -967,13 +987,14 @@
$type = $option->{$var}{type} || "";
$desc = $option->{$var}{description} || "";
$secure = $option->{$var}{secure};
- $secure = 1 if (! defined $secure && $var =~ /pass(word)?$/);
+ $secure = 1 if (! defined $secure && $var =~ /pass(word|wd)?$/);
$secure = $values->{security_policy_level} if (defined $secure &&
defined $values->{security_policy_level});
$val_desc = $option->{$var}{value_description} || "";
$var_str = ($type eq "boolean") ? $var : ($val_desc ?
"$var=<$val_desc>" : "$var=<value>");
$value_str = $secure ? "********" : ((defined $value) ? $value :
"undef");
$type_str = ($type) ? " ($type)" : "";
$desc_str = ($desc) ? " $desc" : "";
+ $desc_str =~ s/%/%%/g;
printf STDERR " --%-32s [%s]$type_str$desc_str\n", $var_str,
$value_str;
}
}