line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::pwhich; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
196313
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
21
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
403
|
use File::Which qw( which ); |
|
1
|
|
|
|
|
949
|
|
|
1
|
|
|
|
|
55
|
|
7
|
1
|
|
|
1
|
|
1705
|
use Getopt::Std qw( getopts ); ## no critic (Community::PreferredAlternatives) |
|
1
|
|
|
|
|
49
|
|
|
1
|
|
|
|
|
380
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Perl-only `which` |
10
|
|
|
|
|
|
|
our $VERSION = '1.17'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub main |
13
|
|
|
|
|
|
|
{ |
14
|
3
|
|
|
3
|
0
|
151141
|
local @ARGV; |
15
|
3
|
|
|
|
|
12
|
my $prog; |
16
|
3
|
|
|
|
|
16
|
($prog, @ARGV) = @_; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
11
|
my %opts; |
19
|
|
|
|
|
|
|
|
20
|
3
|
100
|
|
|
|
12
|
if($prog eq 'which') |
21
|
|
|
|
|
|
|
{ |
22
|
2
|
50
|
|
|
|
11
|
getopts('avs', \%opts) || return _usage(); |
23
|
2
|
50
|
|
|
|
140
|
return _version() if $opts{v}; |
24
|
2
|
50
|
|
|
|
10
|
return _usage() unless @ARGV; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else |
27
|
|
|
|
|
|
|
{ |
28
|
1
|
|
|
|
|
5
|
$opts{a} = 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
14
|
foreach my $file (@ARGV) |
32
|
|
|
|
|
|
|
{ |
33
|
3
|
|
|
|
|
17
|
local $File::Which::IMPLICIT_CURRENT_DIR = $File::Which::IMPLICIT_CURRENT_DIR; |
34
|
3
|
50
|
33
|
|
|
15
|
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
|
|
|
|
25
|
? which($file) |
40
|
|
|
|
|
|
|
: scalar which($file); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# We might end up with @result = (undef) -> 1 elem |
43
|
3
|
50
|
|
|
|
25
|
@result = () unless defined $result[0]; |
44
|
3
|
100
|
|
|
|
10
|
unless($opts{s}) |
45
|
|
|
|
|
|
|
{ |
46
|
2
|
|
|
|
|
9
|
print "$_\n" for grep { defined } @result; |
|
6
|
|
|
|
|
171
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
20
|
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
|
|
|
|
|
16
|
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__ |