App::Whiff - find the first executable of a series of alternatives


App-Whiff documentation Contained in the App-Whiff distribution.

Index


Code Index:

NAME

Top

App::Whiff - find the first executable of a series of alternatives

VERSION

Top

version 0.002

DESCRIPTION

Top

This module implements logic used by the whiff command, which takes a number of command names and returns the first one that exists and is executable.

METHODS

Top

find_first

  my $filename = App::Whiff->find_first(\@names);

Given an arrayref of command names (which should not be anything other than base filename), this method either returns an absolute path to the first of the alternatives found in the path (using File::Which) or false.

run

This method is called by the whiff program to ... well, run.

BUGS

Top

Please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT

Top


App-Whiff documentation Contained in the App-Whiff distribution.
use strict;
use warnings;
package App::Whiff;

our $VERSION = '0.002';

use File::Which;

sub find_first {
  my ($self, $names) = @_;

  my $file;
  for my $name (@$names) {
    $file = File::Which::which($name);
    return $file if $file;
  }

  return;
}

sub run {
  my ($self) = @_;

  die "usage: whiff <command ...>\n" unless @ARGV;
  my $file = $self->find_first([ @ARGV ]);
  die "no alternative found\n" unless $file;
  print "$file\n";
}

1;