File Coverage

blib/lib/App/pwhich.pm
Criterion Covered Total %
statement 27 34 79.4
branch 8 16 50.0
condition 0 2 0.0
subroutine 6 8 75.0
pod 0 1 0.0
total 41 61 67.2


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