| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/File/Which.pm |
| Statements | Executed 22 statements in 626µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 16µs | 16µs | File::Which::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 9µs | File::Which::BEGIN@9 |
| 1 | 1 | 1 | 9µs | 52µs | File::Which::BEGIN@16 |
| 1 | 1 | 1 | 7µs | 37µs | File::Which::BEGIN@18 |
| 1 | 1 | 1 | 7µs | 59µs | File::Which::BEGIN@8 |
| 1 | 1 | 1 | 6µs | 37µs | File::Which::BEGIN@17 |
| 1 | 1 | 1 | 6µs | 17µs | File::Which::BEGIN@4 |
| 1 | 1 | 1 | 3µs | 3µs | File::Which::BEGIN@5 |
| 1 | 1 | 1 | 3µs | 3µs | File::Which::BEGIN@6 |
| 0 | 0 | 0 | 0s | 0s | File::Which::where |
| 0 | 0 | 0 | 0s | 0s | File::Which::which |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package File::Which; | ||||
| 2 | |||||
| 3 | 2 | 34µs | 1 | 16µs | # spent 16µs within File::Which::BEGIN@3 which was called:
# once (16µs+0s) by File::HomeDir::BEGIN@10 at line 3 # spent 16µs making 1 call to File::Which::BEGIN@3 |
| 4 | 2 | 17µs | 2 | 28µs | # spent 17µs (6+11) within File::Which::BEGIN@4 which was called:
# once (6µs+11µs) by File::HomeDir::BEGIN@10 at line 4 # spent 17µs making 1 call to File::Which::BEGIN@4
# spent 11µs making 1 call to strict::import |
| 5 | 2 | 20µs | 1 | 3µs | # spent 3µs within File::Which::BEGIN@5 which was called:
# once (3µs+0s) by File::HomeDir::BEGIN@10 at line 5 # spent 3µs making 1 call to File::Which::BEGIN@5 |
| 6 | 2 | 19µs | 1 | 3µs | # spent 3µs within File::Which::BEGIN@6 which was called:
# once (3µs+0s) by File::HomeDir::BEGIN@10 at line 6 # spent 3µs making 1 call to File::Which::BEGIN@6 |
| 7 | |||||
| 8 | 2 | 37µs | 2 | 112µs | # spent 59µs (7+53) within File::Which::BEGIN@8 which was called:
# once (7µs+53µs) by File::HomeDir::BEGIN@10 at line 8 # spent 59µs making 1 call to File::Which::BEGIN@8
# spent 53µs making 1 call to vars::import |
| 9 | # spent 9µs within File::Which::BEGIN@9 which was called:
# once (9µs+0s) by File::HomeDir::BEGIN@10 at line 14 | ||||
| 10 | 1 | 300ns | $VERSION = '1.09'; | ||
| 11 | 1 | 5µs | @ISA = 'Exporter'; | ||
| 12 | 1 | 500ns | @EXPORT = 'which'; | ||
| 13 | 1 | 4µs | @EXPORT_OK = 'where'; | ||
| 14 | 1 | 24µs | 1 | 9µs | } # spent 9µs making 1 call to File::Which::BEGIN@9 |
| 15 | |||||
| 16 | 2 | 27µs | 2 | 95µs | # spent 52µs (9+43) within File::Which::BEGIN@16 which was called:
# once (9µs+43µs) by File::HomeDir::BEGIN@10 at line 16 # spent 52µs making 1 call to File::Which::BEGIN@16
# spent 43µs making 1 call to constant::import |
| 17 | 2 | 30µs | 2 | 67µs | # spent 37µs (6+30) within File::Which::BEGIN@17 which was called:
# once (6µs+30µs) by File::HomeDir::BEGIN@10 at line 17 # spent 37µs making 1 call to File::Which::BEGIN@17
# spent 30µs making 1 call to constant::import |
| 18 | 2 | 402µs | 2 | 67µs | # spent 37µs (7+30) within File::Which::BEGIN@18 which was called:
# once (7µs+30µs) by File::HomeDir::BEGIN@10 at line 18 # spent 37µs making 1 call to File::Which::BEGIN@18
# spent 30µs making 1 call to constant::import |
| 19 | |||||
| 20 | # For Win32 systems, stores the extensions used for | ||||
| 21 | # executable files | ||||
| 22 | # For others, the empty string is used | ||||
| 23 | # because 'perl' . '' eq 'perl' => easier | ||||
| 24 | 1 | 1µs | my @PATHEXT = (''); | ||
| 25 | if ( IS_DOS ) { | ||||
| 26 | # WinNT. PATHEXT might be set on Cygwin, but not used. | ||||
| 27 | if ( $ENV{PATHEXT} ) { | ||||
| 28 | push @PATHEXT, split ';', $ENV{PATHEXT}; | ||||
| 29 | } else { | ||||
| 30 | # Win9X or other: doesn't have PATHEXT, so needs hardcoded. | ||||
| 31 | push @PATHEXT, qw{.com .exe .bat}; | ||||
| 32 | } | ||||
| 33 | } elsif ( IS_VMS ) { | ||||
| 34 | push @PATHEXT, qw{.exe .com}; | ||||
| 35 | } | ||||
| 36 | |||||
| 37 | sub which { | ||||
| 38 | my ($exec) = @_; | ||||
| 39 | |||||
| 40 | return undef unless $exec; | ||||
| 41 | |||||
| 42 | my $all = wantarray; | ||||
| 43 | my @results = (); | ||||
| 44 | |||||
| 45 | # check for aliases first | ||||
| 46 | if ( IS_VMS ) { | ||||
| 47 | my $symbol = `SHOW SYMBOL $exec`; | ||||
| 48 | chomp($symbol); | ||||
| 49 | unless ( $? ) { | ||||
| 50 | return $symbol unless $all; | ||||
| 51 | push @results, $symbol; | ||||
| 52 | } | ||||
| 53 | } | ||||
| 54 | if ( IS_MAC ) { | ||||
| 55 | my @aliases = split /\,/, $ENV{Aliases}; | ||||
| 56 | foreach my $alias ( @aliases ) { | ||||
| 57 | # This has not been tested!! | ||||
| 58 | # PPT which says MPW-Perl cannot resolve `Alias $alias`, | ||||
| 59 | # let's just hope it's fixed | ||||
| 60 | if ( lc($alias) eq lc($exec) ) { | ||||
| 61 | chomp(my $file = `Alias $alias`); | ||||
| 62 | last unless $file; # if it failed, just go on the normal way | ||||
| 63 | return $file unless $all; | ||||
| 64 | push @results, $file; | ||||
| 65 | # we can stop this loop as if it finds more aliases matching, | ||||
| 66 | # it'll just be the same result anyway | ||||
| 67 | last; | ||||
| 68 | } | ||||
| 69 | } | ||||
| 70 | } | ||||
| 71 | |||||
| 72 | my @path = File::Spec->path; | ||||
| 73 | if ( IS_DOS or IS_VMS or IS_MAC ) { | ||||
| 74 | unshift @path, File::Spec->curdir; | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | foreach my $base ( map { File::Spec->catfile($_, $exec) } @path ) { | ||||
| 78 | for my $ext ( @PATHEXT ) { | ||||
| 79 | my $file = $base.$ext; | ||||
| 80 | |||||
| 81 | # We don't want dirs (as they are -x) | ||||
| 82 | next if -d $file; | ||||
| 83 | |||||
| 84 | if ( | ||||
| 85 | # Executable, normal case | ||||
| 86 | -x _ | ||||
| 87 | or ( | ||||
| 88 | # MacOS doesn't mark as executable so we check -e | ||||
| 89 | IS_MAC | ||||
| 90 | || | ||||
| 91 | ( | ||||
| 92 | IS_DOS | ||||
| 93 | and | ||||
| 94 | grep { | ||||
| 95 | $file =~ /$_\z/i | ||||
| 96 | } @PATHEXT[1..$#PATHEXT] | ||||
| 97 | ) | ||||
| 98 | # DOSish systems don't pass -x on | ||||
| 99 | # non-exe/bat/com files. so we check -e. | ||||
| 100 | # However, we don't want to pass -e on files | ||||
| 101 | # that aren't in PATHEXT, like README. | ||||
| 102 | and -e _ | ||||
| 103 | ) | ||||
| 104 | ) { | ||||
| 105 | return $file unless $all; | ||||
| 106 | push @results, $file; | ||||
| 107 | } | ||||
| 108 | } | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | if ( $all ) { | ||||
| 112 | return @results; | ||||
| 113 | } else { | ||||
| 114 | return undef; | ||||
| 115 | } | ||||
| 116 | } | ||||
| 117 | |||||
| 118 | sub where { | ||||
| 119 | # force wantarray | ||||
| 120 | my @res = which($_[0]); | ||||
| 121 | return @res; | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | 1 | 3µs | 1; | ||
| 125 | |||||
| 126 | __END__ |