App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Options.pm view on Meta::CPAN
# Create full entry
$options_fields_href->{$field} = {
'field'=>$field,
'spec'=>$option_spec,
'summary'=>$summary,
'description'=>$description,
'default'=>$default_val,
'pod_spec'=>$spec,
'type' => $arg_type,
'dest_type' => $dest_type,
'developer' => $developer_only,
'entry' => $option_entry_aref,
'owner' => $owner_pkg,
} ;
# add to list of names
push @$option_names_aref, $field ;
}
$this->_dbg_prt( ["update() set: Getopts spec=", $get_options_aref] , 2) ;
$this->_dbg_prt( ["update() - END\n"], 2 ) ;
## Save
$this->_options_list($options_aref) ;
$this->_options($options_href) ;
$this->_get_options($get_options_aref) ;
$this->_option_fields_hash($options_fields_href) ;
$this->option_names($option_names_aref) ;
return %$options_href ;
}
#----------------------------------------------------------------------------
=item B<append_options($options_aref [, $caller_pkg])>
Append the options listed in the ARRAY ref I<$options_aref> to the current options list
Each entry in the ARRAY ref is an ARRAY ref containing:
[ <option spec>, <option summary>, <option description>, <option default> ]
Where the <option spec> is in the format <name><specification> (see L</name> and L</specification> above). The summary and description
are as describe in L</Option Definition>. The optional default value is just the value (rather than the string '[default=...]').
Can optionally specify the caller package name (otherwise works out the caller and stores that package name)
=cut
sub append_options
{
my $this = shift ;
my ($options_aref, $caller_pkg) = @_ ;
$this->_dbg_prt( ["Options: append_options()\n"] ) ;
# get caller
unless ($caller_pkg)
{
$caller_pkg = (caller(0))[0] ;
}
my @combined_options = (@{$this->user_options}) ;
foreach my $opt_aref (@$options_aref)
{
my @opt = ($opt_aref->[0], $opt_aref->[1], $opt_aref->[2], $opt_aref->[3], $caller_pkg) ;
push @combined_options, \@opt ;
}
$this->user_options(\@combined_options) ;
$this->_dbg_prt( ["Options: append_options() new=", $options_aref] , 2) ;
$this->_dbg_prt( ["combined=", \@combined_options] , 2) ;
## Build new set of options
$this->update() ;
return @combined_options ;
}
#----------------------------------------------------------------------------
=item B<clear_options()>
Clears the current options list.
=cut
sub clear_options
{
my $this = shift ;
$this->_dbg_prt( ["Options: clear_options()\n"] ) ;
$this->user_options([]) ;
}
#----------------------------------------------------------------------------
=item B<get_options()>
Use Getopt::Long to process the command line options. Returns 1 on success; 0 otherwise
=cut
sub get_options
{
my $this = shift ;
# Do final processing of the options
$this->update() ;
# get the list suitable for GetOpts
my $get_options_aref = $this->_get_options() ;
$this->_dbg_prt( ["get_options() : ARGV=", \@ARGV, " Options=", $get_options_aref], 2 ) ;
# Parse options using GetOpts
my $ok = GetOptions(@$get_options_aref) ;
( run in 0.527 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )