line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
524
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
29
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
49
|
|
|
1
|
|
|
|
|
74
|
|
3
|
|
|
|
|
|
|
package App::Whiff 0.007; |
4
|
|
|
|
|
|
|
# ABSTRACT: find the first executable of a series of alternatives |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
522
|
use File::Which (); |
|
1
|
|
|
|
|
1248
|
|
|
1
|
|
|
|
|
177
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
9
|
|
|
|
|
|
|
#pod |
10
|
|
|
|
|
|
|
#pod This module implements logic used by the F command, which takes a number |
11
|
|
|
|
|
|
|
#pod of command names and returns the first one that exists and is executable. |
12
|
|
|
|
|
|
|
#pod |
13
|
|
|
|
|
|
|
#pod =method find_first |
14
|
|
|
|
|
|
|
#pod |
15
|
|
|
|
|
|
|
#pod my $filename = App::Whiff->find_first(\@names); |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod Given an arrayref of command names (which should I be anything other than |
18
|
|
|
|
|
|
|
#pod base filename), this method either returns an absolute path to the first of the |
19
|
|
|
|
|
|
|
#pod alternatives found in the path (using L) or false. |
20
|
|
|
|
|
|
|
#pod |
21
|
|
|
|
|
|
|
#pod =cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub find_first { |
24
|
0
|
|
|
0
|
1
|
|
my ($self, $names) = @_; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $file; |
27
|
0
|
|
|
|
|
|
for my $name (@$names) { |
28
|
0
|
0
|
0
|
|
|
|
return $name if $name =~ m{\A/} && -x $name; |
29
|
0
|
|
|
|
|
|
$file = File::Which::which($name); |
30
|
0
|
0
|
|
|
|
|
return $file if $file; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#pod =method run |
37
|
|
|
|
|
|
|
#pod |
38
|
|
|
|
|
|
|
#pod This method is called by the F program to ... well, run. |
39
|
|
|
|
|
|
|
#pod |
40
|
|
|
|
|
|
|
#pod =cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub run { |
43
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
die "usage: whiff \n" unless @ARGV; |
46
|
0
|
|
|
|
|
|
my $file = $self->find_first([ @ARGV ]); |
47
|
0
|
0
|
|
|
|
|
die "no alternative found\n" unless $file; |
48
|
0
|
|
|
|
|
|
print "$file\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |