App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Options.pm view on Meta::CPAN
#----------------------------------------------------------------------------
=item B< options() >
Feature accessor method (aliases on the app object as B<options>)
Returns the hash of options/values
=cut
sub options
{
my $this = shift ;
$this->_dbg_prt( ["Options()\n"] ) ;
my $options_href = $this->_options() ;
return %$options_href ;
}
#----------------------------------------------------------------------------
=item B< Options([%args]) >
Alias to L</options>
=cut
*Options = \&options ;
#----------------------------------------------------------------------------
=item B<option($option_name)>
Returns the value of the named option
=cut
sub option
{
my $this = shift ;
my ($option_name) = @_ ;
my $options_href = $this->_options() ;
return exists($options_href->{$option_name}) ? $options_href->{$option_name} : undef ;
}
#----------------------------------------------------------------------------
=item B< update() >
(Called by App::Framework::Core)
Take the list of options (created by calls to L</append_options>) and process the list into the
final options list.
Returns the hash of options/values
=cut
sub update
{
my $this = shift ;
$this->_dbg_prt( ["update()\n"] ) ;
if ( $this->debug()>=2 )
{
$this->dump_callstack() ;
}
## get user settings
my $options_aref = $this->user_options ;
## set up internals
# rebuild these
my $options_href = {} ;
my $get_options_aref = [] ;
my $option_names_aref = [] ;
# keep full details
# my $options_fields_href = $this->_option_fields_hash($options_fields_href) ;
my $options_fields_href = {} ;
## process to see if any options are to be over-ridden
my %options ;
my @processed_options ;
foreach my $option_aref (@$options_aref)
{
my ($spec, $summary, $default_val, $description) = @$option_aref ;
# split spec into the field names
my ($field, $option_spec, $pod_spec, $dest_type, $developer_only, $fields_aref, $arg_type) =
$this->_process_option_spec($spec) ;
# see if any fields have been seen before
my $in_list = 0 ;
foreach my $fnm (@$fields_aref)
{
$this->_dbg_prt( ["opt: Checking '$fnm' ($option_aref)..\n"], 2 ) ;
if (exists($options{$fnm}))
{
$this->_dbg_prt( ["opt: '$fnm' seen before\n"], 2 ) ;
# seen before - overwrite settings
my $aref = $options{$fnm} ;
$in_list = 1;
# [$spec, $summary, $description, $default_val]
for (my $i=1; $i < scalar(@$option_aref); $i++)
{
$this->_dbg_prt( ["opt: checking $i\n"], 2 ) ;
# if newer entry is set to something then use it
if ($option_aref->[$i])
{
my $old = $aref->[$i] || '' ;
$this->_dbg_prt( ["opt: overwrite $i : '$old' with '$option_aref->[$i]'\n"], 2 ) ;
$aref->[$i] = $option_aref->[$i] ;
}
( run in 1.104 second using v1.01-cache-2.11-cpan-39bf76dae61 )