App-Framework-Lite
view release on metacpan or search on metacpan
lib/App/Framework/Lite.pm view on Meta::CPAN
sub get_synopsis
{
my $this = shift ;
my $synopsis = $this->{synopsis} ;
if (!$synopsis)
{
my %opts = $this->options() ;
# start with basics
my $app = $this->{name} ;
$synopsis = "$app [options] " ;
## Get args
my $names_aref = $this->{arg_names} ;
foreach my $arg_name (@$names_aref)
{
my $arg_entry_href = $this->arg_entry($arg_name) ;
my $type = "" ;
if ($arg_entry_href->{'type'} eq 'f')
{
$type = "file" ;
}
if ($arg_entry_href->{'type'} eq 'd')
{
$type = "directory" ;
}
if ($type)
{
my $direction = "input " ;
if ($arg_entry_href->{'direction'} eq 'o')
{
$direction = "output " ;
}
$type = " ($direction $type)" ;
}
my $suffix = "" ;
if ($arg_entry_href->{'dest_type'})
{
$suffix = "(s)" ;
}
if ($arg_entry_href->{'optional'})
{
$synopsis .= 'I<[' ;
}
else
{
$synopsis .= 'B<' ;
}
$synopsis .= "{$arg_name$type$suffix}" ;
$synopsis .= ']' if $arg_entry_href->{'optional'} ;
$synopsis .= '> ' ;
}
# set our best guess
$this->{synopsis} = $synopsis ;
}
return $synopsis ;
}
#============================================================================================
# RUN
#============================================================================================
#-----------------------------------------------------------------------------
=item B<required([$required_href])>
Get/set the required programs list. If specified, B<$required_href> is a HASH ref where the
keys are the names of the required programs (the values are unimportant).
This method returns the B<$required_href> HASH ref having set the values associated with the
program name keys to the path for that program. Where a program is not found then
it's path is set to undef.
Also, if the L</on_error> field is set to 'warning' or 'fatal' then this method throws a warning
or fatal error if one or more required programs are not found. Sets the message string to indicate
which programs were not found.
=cut
sub required
{
my $this = shift ;
my ($new_required_href) = @_ ;
my $required_href = $this->{'required'} ;
if ($new_required_href)
{
## Test for available executables
foreach my $exe (keys %$new_required_href)
{
# only do this is we have File::Which
if ($AVAILABLE_MOD{'File::Which'})
{
$required_href->{$exe} = which($exe) ;
}
else
{
$required_href->{$exe} = 1 ;
}
}
## check for errors
my $throw = $this->_throw_on_error($this->{on_error}) ;
if ($throw)
{
my $error = "" ;
foreach my $exe (keys %$new_required_href)
{
if (!$required_href->{$exe})
{
$error .= " $exe\n" ;
( run in 1.179 second using v1.01-cache-2.11-cpan-39bf76dae61 )