App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Args.pm view on Meta::CPAN
$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 ;
}
$this->_dbg_prt(["update() - END\n"], 2) ;
## Save
$this->arg_names($args_list) ;
$this->_args($args_href) ;
$this->_arg_names_hash($args_names_href) ;
return %$args_href ;
}
#-----------------------------------------------------------------------------
=item B< check_args() >
At start of application, check the arguments for valid files etc.
=cut
sub check_args
{
my $this = shift ;
# specified args
my $argv_aref = $this->argv ;
# values
my $args_href = $this->_args() ;
# details
my $arg_names_href = $this->_arg_names_hash() ;
# File handles
my $fh_aref = $this->_fh_list() ;
$this->_dbg_prt(["check_args() Names=", $arg_names_href, "Values=", $args_href, "Name list=", $this->arg_names()], 2) ;
## Check feature settings
my ($open_out, $open_in) = (1, 1) ;
my $feature_args = $this->feature_args ;
if ($feature_args =~ m/open\s*=\s*(out|in|no)/i)
{
if ($1 =~ /out/i)
{
++$open_out ;
( run in 0.795 second using v1.01-cache-2.11-cpan-39bf76dae61 )