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