Add built local::lib
[catagits/Gitalist.git] / local-lib5 / bin / pwhich
1 #!/usr/bin/perl
2
3 eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
4     if 0; # not running under some shell
5
6 use 5.004;
7 use strict;
8 use File::Which ();
9 use Getopt::Std ();
10
11 use vars qw{$VERSION};
12 BEGIN {
13         $VERSION = '1.09';
14 }
15
16 # Handle options
17 my %opts = ();
18 Getopt::Std::getopts('av', \%opts);
19
20 if ( $opts{v} ) {
21         print <<"END_TEXT";
22 This is pwhich running File::Which version $File::Which::VERSION
23
24 Copyright 2002 Per Einar Ellefsen.
25
26 Some parts copyright 2009 Adam Kennedy.
27
28 This program is free software; you can redistribute it and/or modify
29 it under the same terms as Perl itself.
30 END_TEXT
31
32         exit(0);
33 }
34
35 unless ( @ARGV ) {
36         print <<"END_TEXT";
37 Usage: $0 [-a] [-v] programname [programname ...]
38       -a        Print all matches in PATH, not just the first.
39       -v        Prints version and exits
40
41 END_TEXT
42
43         exit(0);
44 }
45
46 foreach my $file ( @ARGV ) {
47         my @result = $opts{a}
48                 ? File::Which::which($file)
49                 # Need to force scalar
50                 : scalar File::Which::which($file);
51
52         # We might end up with @result = (undef) -> 1 elem
53         @result = () unless defined $result[0];
54         foreach my $result ( @result ) {
55                 print "$result\n" if $result;
56         }
57         unless ( @result ) {
58                 print STDERR "pwhich: no $file in PATH\n";
59                 exit(255);
60         }
61 }
62
63 exit(0);
64
65 __END__
66
67 =pod
68
69 =head1 NAME
70
71 pwhich - Perl-only `which'
72
73 =head1 SYNOPSIS
74
75   $ pwhich perl
76   $ pwhich -a perl          # print all matches
77   $ pwhich perl perldoc ... # look for multiple programs
78   $ pwhich -a perl perldoc ...
79
80 =head1 DESCRIPTION
81
82 `pwhich' is a command-line utility program for finding paths to other
83 programs based on the user's C<PATH>. It is similar to the usualy Unix
84 tool `which', and tries to emulate its functionality, but is written
85 purely in Perl (uses the module C<File::Which>), so is portable.
86
87 =head2 Calling syntax
88
89   $ pwhich [-a] [-v] programname [programname ...]
90
91 =head2 Options
92
93 =over
94
95 =item -a
96
97 The option I<-a> will make C<pwhich> print all matches found in the
98 C<PATH> variable instead of just the first one. Each match is printed
99 on a separate line.
100
101 =item -v
102
103 Prints version (of C<File::Which>) and copyright notice and exits.
104
105 =back
106
107 =head1 SUPPORT
108
109 Bugs should be reported via the CPAN bug tracker at
110
111 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Which>
112
113 For other issues, contact the maintainer.
114
115 =head1 AUTHOR
116
117 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
118
119 Per Einar Ellefsen E<lt>pereinar@cpan.orgE<gt>
120
121 Originated in F<modperl-2.0/lib/Apache/Build.pm>. Changed for use in DocSet
122 (for the mod_perl site) and Win32-awareness by me, with slight modifications
123 by Stas Bekman, then extracted to create C<File::Which>.
124
125 Version 0.04 had some significant platform-related changes, taken from
126 the Perl Power Tools C<`which'> implementation by Abigail with
127 enhancements from Peter Prymmer. See
128 L<http://www.perl.com/language/ppt/src/which/index.html> for more
129 information.
130
131 =head1 COPYRIGHT
132
133 Copyright 2002 Per Einar Ellefsen.
134
135 Some parts copyright 2009 Adam Kennedy.
136
137 This program is free software; you can redistribute it and/or modify
138 it under the same terms as Perl itself.
139
140 =head1 SEE ALSO
141
142 L<perl>, L<File::Which>, L<which(1)>
143
144 =cut