App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Args.pm view on Meta::CPAN
#----------------------------------------------------------------------------
=item B< arg_hash() >
Returns the full arguments hash.
=cut
sub arg_hash
{
my $this = shift ;
my $args_href = $this->_args() ;
return %$args_href ;
}
#----------------------------------------------------------------------------
=item B<append_args($args_aref)>
Append the options listed in the ARRAY ref I<$args_aref> to the current args list
=cut
sub append_args
{
my $this = shift ;
my ($args_aref) = @_ ;
$this->_dbg_prt(["Args: append_args()\n"]) ;
my @combined_args = (@{$this->user_args}, @$args_aref) ;
$this->user_args(\@combined_args) ;
$this->_dbg_prt(["Options: append_args() new=", $args_aref], 2) ;
$this->_dbg_prt(["combined=", \@combined_args], 2) ;
## Build new set of args
$this->update() ;
return @combined_args ;
}
#----------------------------------------------------------------------------
=item B< update() >
Take the list of args (created by calls to L</append_args>) and process the list into the
final args list.
Each entry in the ARRAY is an ARRAY ref containing:
[ <arg spec>, <arg summary>, <arg description>, <arg default> ]
Returns the hash of args/values
=cut
sub update
{
my $this = shift ;
$this->_dbg_prt(["Args: update()\n"]) ;
## get user settings
my $args_aref = $this->user_args ;
## set up internals
# rebuild these
my $args_href = {} ;
# keep full details
my $args_names_href = {} ;
## fill args_href, get_args_aref
my $args_list = [] ;
# Cycle through
my $optional = 0 ;
my $last_dest_type ;
foreach my $arg_entry_aref (@$args_aref)
{
$this->_dbg_prt(["Arg entry=", $arg_entry_aref], 2) ;
my ($arg_spec, $summary, $description, $default_val) = @$arg_entry_aref ;
## Process the arg spec
my ($name, $pod_spec, $dest_type, $arg_type, $arg_direction, $arg_optional, $arg_append, $arg_mode) ;
($name, $arg_spec, $pod_spec, $dest_type, $arg_type, $arg_direction, $arg_optional, $arg_append, $arg_mode) =
$this->_process_arg_spec($arg_spec) ;
if ($last_dest_type)
{
$this->throw_fatal("Application definition error: arg $name defined after $last_dest_type defined as array") ;
}
$last_dest_type = $name if $dest_type ;
# Set default if required
$args_href->{$name} = $default_val if (defined($default_val)) ;
# See if optional
$arg_optional++ if defined($default_val) ;
if ($optional && !$arg_optional)
{
$this->throw_fatal("Application definition error: arg $name should be optional since previous arg is") ;
}
$optional ||= $arg_optional ;
$this->_dbg_prt(["Args: update() - arg_optional=$arg_optional optional=$optional\n"]) ;
# Create full entry
my $href = $this->_new_arg_entry($name, $arg_spec, $summary, $description, $default_val, $pod_spec, $arg_type, $arg_direction, $dest_type, $optional, $arg_append, $arg_mode) ;
$args_names_href->{$name} = $href ;
$this->_dbg_prt(["Arg $name HASH=", $href], 2) ;
# save arg in specified order
push @$args_list, $name ;
( run in 0.706 second using v1.01-cache-2.11-cpan-df04353d9ac )