line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::pwhich; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
207714
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
57
|
use 5.008001; |
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
482
|
use File::Which qw( which ); |
|
1
|
|
|
|
|
962
|
|
|
1
|
|
|
|
|
54
|
|
7
|
1
|
|
|
1
|
|
1884
|
use Getopt::Std qw( getopts ); |
|
1
|
|
|
|
|
46
|
|
|
1
|
|
|
|
|
431
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Perl-only `which` |
10
|
|
|
|
|
|
|
our $VERSION = '1.16'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub main |
13
|
|
|
|
|
|
|
{ |
14
|
3
|
|
|
3
|
0
|
174231
|
local @ARGV; |
15
|
3
|
|
|
|
|
8
|
my $prog; |
16
|
3
|
|
|
|
|
18
|
($prog, @ARGV) = @_; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
17
|
my %opts; |
19
|
|
|
|
|
|
|
|
20
|
3
|
100
|
|
|
|
23
|
if($prog eq 'which') |
21
|
|
|
|
|
|
|
{ |
22
|
2
|
50
|
|
|
|
19
|
getopts('avs', \%opts) || return _usage(); |
23
|
2
|
50
|
|
|
|
170
|
return _version() if $opts{v}; |
24
|
2
|
50
|
|
|
|
7
|
return _usage() unless @ARGV; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else |
27
|
|
|
|
|
|
|
{ |
28
|
1
|
|
|
|
|
10
|
$opts{a} = 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
12
|
foreach my $file (@ARGV) |
32
|
|
|
|
|
|
|
{ |
33
|
3
|
|
|
|
|
11
|
local $File::Which::IMPLICIT_CURRENT_DIR = $File::Which::IMPLICIT_CURRENT_DIR; |
34
|
3
|
50
|
33
|
|
|
21
|
if($^O eq 'MSWin32' && eval { require Shell::Guess; 1 }) |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
0
|
$File::Which::IMPLICIT_CURRENT_DIR = !Shell::Guess->running_shell->is_power; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
my @result = $opts{a} |
39
|
3
|
50
|
|
|
|
17
|
? which($file) |
40
|
|
|
|
|
|
|
: scalar which($file); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# We might end up with @result = (undef) -> 1 elem |
43
|
3
|
50
|
|
|
|
26
|
@result = () unless defined $result[0]; |
44
|
3
|
100
|
|
|
|
24
|
unless($opts{s}) |
45
|
|
|
|
|
|
|
{ |
46
|
2
|
|
|
|
|
13
|
print "$_\n" for grep { defined } @result; |
|
6
|
|
|
|
|
142
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
23
|
unless (@result) |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
0
|
|
|
|
0
|
print STDERR "$0: no $file in PATH\n" unless $opts{s}; |
52
|
0
|
|
|
|
|
0
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
56
|
return 0; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _version |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
0
|
0
|
|
|
my $my_version = $App::pwhich::VERSION || 'dev'; |
62
|
0
|
|
|
|
|
|
print <<"END_TEXT"; |
63
|
|
|
|
|
|
|
This is pwhich running File::Which version $File::Which::VERSION |
64
|
|
|
|
|
|
|
App::pwhich version $my_version |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Copyright 2002 Per Einar Ellefsen |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Some parts Copyright 2009 Adam Kennedy |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Other parts Copyright 2015 Graham Ollis |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
73
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
74
|
|
|
|
|
|
|
END_TEXT |
75
|
0
|
|
|
|
|
|
2; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _usage |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
0
|
|
|
print <<"END_TEXT"; |
81
|
|
|
|
|
|
|
Usage: $0 [-a] [-s] [-v] programname [programname ...] |
82
|
|
|
|
|
|
|
-a Print all matches in PATH, not just the first. |
83
|
|
|
|
|
|
|
-v Prints version and exits |
84
|
|
|
|
|
|
|
-s Silent mode |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
END_TEXT |
87
|
0
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |