App-Basis
view release on metacpan or search on metacpan
lib/App/Basis.pm view on Meta::CPAN
my $_test_mode = 0 ;
# ----------------------------------------------------------------------------
# control how we output things to help with testing
sub _output
{
my ( $where, $msg ) = @_ ;
if ( !$_test_mode ) {
if ( $where =~ /stderr/i ) {
say STDERR $msg ;
} else {
say $msg ;
}
}
}
# ----------------------------------------------------------------------------
lib/App/Basis.pm view on Meta::CPAN
my ( $cmd, $timeout ) = @_ ;
# use our local version of path so that it can pass taint checks
local $ENV{PATH} = $ENV{PATH} ;
# pass everything thought encode incase there is utf8 there
utf8::encode($cmd) ;
my %data = ( command => $cmd ) ;
$data{timeout} = $timeout if ($timeout) ;
my ( $ret, $err, $full_buff, $stdout_buff, $stderr_buff ) = run(%data) ;
my $stdout = join( "\n", @{$stdout_buff} ) ;
my $stderr = join( "\n", @{$stderr_buff} ) ;
return ( !$ret, $stdout, $stderr ) ;
}
# -----------------------------------------------------------------------------
sub fix_filename
{
my $file = shift ;
return if ( !$file ) ;
lib/App/Basis.pm view on Meta::CPAN
One of thses is to make it easy to get parameters from the command line. Obviously you can play with Getopt::Long and
continuously write the same code and add in your own handlers for help etc, but then your co-workers and friends
make not be so consistent, leading to scripts that have no help and take lots of cryptic parameters.
So I created this module to help with command line arguments and displaying help, then I added L<App::Basis::Config> because
everyone needs config files and does not want to constantly repeat themselves there either.
So how is better than other similar modules? I can't say that it is, but it meets my needs.
There is app help available, there is basic debug functionality, which you can extend using your own function,
you can daemonise your script or run a shell command and get the output/stderr/return code.
If you choose to use App::Basis::Config then you will find easy methods to manage reading/saving YAML based config data.
There are (or will be) other App::Basis modules available to help you write scripts without you having to do complex things
or write lots of code.
There is a helper script to create the boilerplate for an appbasis script, see L<appbasis>
=head1 NAME
lib/App/Basis.pm view on Meta::CPAN
execute_cmd(command => ['/my/command','--args'], timeout => 10);
Executes a command using IPC::Cmd::run_forked, less restrictive than run_cmd
see L<IPC::Cmd> for more options that
Input hashref
command - string to execute (arrayrefs aren't supported, for some reason)
timeout - timeout (in seconds) before command is killed
stdout_handler - see IPC::Cmd docs
stderr_handler - see IPC::Cmd docs
child_stdin - pass data to STDIN of forked processes
discard_output - don't return output in hash
terminate_on_parent_sudden_death
Output HASHREF
exit_code - exit code
timeout - time taken to timeout or 0 if timeout not used
stdout - text written to STDOUT
stderr - text written to STDERR
merged - stdout and stderr merged into one stream
err_msg - description of any error that occurred.
=item run_cmd
Basic way to run a shell program and get its output, this is not interactive.
For interactiviness see execute_cmd.
By default if you do not pass a full path to the command, then unless the command
is in /bin, /usr/bin, /usr/local/bin then the command will not run.
( run in 0.478 second using v1.01-cache-2.11-cpan-49f99fa48dc )