← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/File/Which.pm
StatementsExecuted 22 statements in 626µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsFile::Which::::BEGIN@3File::Which::BEGIN@3
1119µs9µsFile::Which::::BEGIN@9File::Which::BEGIN@9
1119µs52µsFile::Which::::BEGIN@16File::Which::BEGIN@16
1117µs37µsFile::Which::::BEGIN@18File::Which::BEGIN@18
1117µs59µsFile::Which::::BEGIN@8File::Which::BEGIN@8
1116µs37µsFile::Which::::BEGIN@17File::Which::BEGIN@17
1116µs17µsFile::Which::::BEGIN@4File::Which::BEGIN@4
1113µs3µsFile::Which::::BEGIN@5File::Which::BEGIN@5
1113µs3µsFile::Which::::BEGIN@6File::Which::BEGIN@6
0000s0sFile::Which::::whereFile::Which::where
0000s0sFile::Which::::whichFile::Which::which
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package File::Which;
2
3234µs116µs
# spent 16µs within File::Which::BEGIN@3 which was called: # once (16µs+0s) by File::HomeDir::BEGIN@10 at line 3
use 5.004;
# spent 16µs making 1 call to File::Which::BEGIN@3
4217µs228µ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
use strict;
# spent 17µs making 1 call to File::Which::BEGIN@4 # spent 11µs making 1 call to strict::import
5220µs13µs
# spent 3µs within File::Which::BEGIN@5 which was called: # once (3µs+0s) by File::HomeDir::BEGIN@10 at line 5
use Exporter ();
# spent 3µs making 1 call to File::Which::BEGIN@5
6219µs13µs
# spent 3µs within File::Which::BEGIN@6 which was called: # once (3µs+0s) by File::HomeDir::BEGIN@10 at line 6
use File::Spec ();
# spent 3µs making 1 call to File::Which::BEGIN@6
7
8237µs2112µ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
use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK};
# 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
BEGIN {
101300ns $VERSION = '1.09';
1115µs @ISA = 'Exporter';
121500ns @EXPORT = 'which';
1314µs @EXPORT_OK = 'where';
14124µs19µs}
# spent 9µs making 1 call to File::Which::BEGIN@9
15
16227µs295µ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
use constant IS_VMS => ($^O eq 'VMS');
# spent 52µs making 1 call to File::Which::BEGIN@16 # spent 43µs making 1 call to constant::import
17230µs267µ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
use constant IS_MAC => ($^O eq 'MacOS');
# spent 37µs making 1 call to File::Which::BEGIN@17 # spent 30µs making 1 call to constant::import
182402µs267µ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
use constant IS_DOS => ($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'os2');
# 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
2411µsmy @PATHEXT = ('');
25if ( 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
37sub 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
118sub where {
119 # force wantarray
120 my @res = which($_[0]);
121 return @res;
122}
123
12413µs1;
125
126__END__