App-Dispatch
view release on metacpan or search on metacpan
NAME
App::Dispatch - Tool to have #! dispatch to the best executable for the
job.
DESCRIPTION
App::Dispatch is an alternative to "/usr/bin/env". Unlike
"/usr/bin/env", it does not rely on your environment to tell it which
program to use. You can set system-wide, and user level configurations
for which program to use. You can also specify a cascade of aliases
and/or paths to search.
Lately it has been a trend to avoid the system install of programming
languages, Perl, Ruby, Python, etc, in most cases it is recommended that
you do not use the system installation of the language. A result of this
is heavy use of "#!/usr/bin/env" to lookup the correct binary to execute
based on your $PATH. The problem with "/usr/bin/env" is that you may not
always have control over the environment. For example if you have a
script that you must run with sudo, your $PATH will be reset.
bin/app_dispatch view on Meta::CPAN
}
sub dispatch {
my $self = shift;
my ( $program, @argv ) = @_;
die "No program specified\n" unless $program;
return $self->debug if $program eq 'DEBUG';
my @cascade;
unshift @cascade => shift @argv while @argv && $argv[0] ne '--';
shift @argv;
@cascade = ( 'DEFAULT', 'SYSTEM' ) unless @cascade;
my $conf = $self->programs->{$program} || {};
my $run;
for my $item (@cascade) {
if ( $item eq 'ENV' ) {
$run = $program;
}
elsif ( my $alias = $conf->{$item} ) {
next unless -x $alias;
$run = $alias;
}
elsif ( -x $item ) {
$run = $item;
}
}
exec( $run, @argv ) if $run;
print STDERR "Could not find valid '$program' to run.\n";
print STDERR "Searched: " . join( ', ', @cascade ) . "\n";
print STDERR "'$program' config: ";
if ( keys %$conf ) {
print "\n";
for my $alias ( keys %$conf ) {
print STDERR " $alias = $conf->{$alias}\n";
}
}
else {
print STDERR "No config for '$program'\n";
}
lib/App/Dispatch.pm view on Meta::CPAN
=head1 NAME
App::Dispatch - Tool to have #! dispatch to the best executable for the job.
=head1 DESCRIPTION
App::Dispatch is an alternative to C</usr/bin/env>. Unlike C</usr/bin/env>, it
does not rely on your environment to tell it which program to use. You can set
system-wide, and user level configurations for which program to use. You can
also specify a cascade of aliases and/or paths to search.
Lately it has been a trend to avoid the system install of programming
languages, Perl, Ruby, Python, etc, in most cases it is recommended that you do
not use the system installation of the language. A result of this is heavy use
of C<#!/usr/bin/env> to lookup the correct binary to execute based on your
C<$PATH>. The problem with C</usr/bin/env> is that you may not always have
control over the environment. For example if you have a script that you must
run with sudo, your C<$PATH> will be reset.
With App::Dispatch you can specify multiple locations to try when looking for
( run in 0.520 second using v1.01-cache-2.11-cpan-49f99fa48dc )