summaryrefslogtreecommitdiff
path: root/perl5
diff options
context:
space:
mode:
Diffstat (limited to 'perl5')
-rw-r--r--perl5/Local/Util.pm13
1 files changed, 12 insertions, 1 deletions
diff --git a/perl5/Local/Util.pm b/perl5/Local/Util.pm
index a9d3d13f..edba6d07 100644
--- a/perl5/Local/Util.pm
+++ b/perl5/Local/Util.pm
@@ -20,7 +20,7 @@ use warnings;
use Exporter 'import';
-our @EXPORT_OK = qw(as_root);
+our @EXPORT_OK = qw(as_root executable_find);
# Prefix a command if that's necessary to run it as root. Currently
# supports only sudo(1). If passed more than one argument, prepends
@@ -47,4 +47,15 @@ sub as_root {
}
}
+=head executable_find($name)
+
+Return the full path to $name if it is on PATH, else error.
+
+=cut
+
+sub executable_find {
+ chomp(my $output = `sh -c "command -v $_[0]"`);
+ $? == 0 ? return $output : die "$_[0] not found on PATH"
+}
+
1;