Filename | /usr/share/perl/5.18/File/stat.pm |
Statements | Executed 65 statements in 1.78ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.13ms | 6.68ms | BEGIN@184 | File::stat::
1 | 1 | 1 | 343µs | 780µs | BEGIN@30 | File::stat::
1 | 1 | 1 | 65µs | 86µs | BEGIN@32 | File::stat::
1 | 1 | 1 | 12µs | 12µs | BEGIN@2 | File::stat::
1 | 1 | 1 | 10µs | 42µs | BEGIN@158 | File::stat::
1 | 1 | 1 | 9µs | 9µs | BEGIN@16 | File::stat::
1 | 1 | 1 | 7µs | 44µs | BEGIN@154 | File::stat::
1 | 1 | 1 | 7µs | 98µs | BEGIN@6 | File::stat::
1 | 1 | 1 | 7µs | 44µs | BEGIN@7 | File::stat::
1 | 1 | 1 | 7µs | 17µs | BEGIN@211 | File::stat::
1 | 1 | 1 | 6µs | 14µs | BEGIN@35 | File::stat::
1 | 1 | 1 | 6µs | 134µs | BEGIN@28 | File::stat::
1 | 1 | 1 | 6µs | 6µs | import | File::stat::
1 | 1 | 1 | 5µs | 13µs | BEGIN@4 | File::stat::
1 | 1 | 1 | 5µs | 9µs | BEGIN@5 | File::stat::
1 | 1 | 1 | 3µs | 3µs | BEGIN@17 | File::stat::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:116] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:123] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:124] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:125] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:126] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:128] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:129] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:130] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:131] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:133] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:134] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:135] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:137] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:138] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:139] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:140] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:141] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:142] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:143] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:145] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:146] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:147] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:149] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:150] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:151] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:179] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:38] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:42] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:47] | File::stat::
0 | 0 | 0 | 0s | 0s | __ANON__[:82] | File::stat::
0 | 0 | 0 | 0s | 0s | _ingroup | File::stat::
0 | 0 | 0 | 0s | 0s | lstat | File::stat::
0 | 0 | 0 | 0s | 0s | populate | File::stat::
0 | 0 | 0 | 0s | 0s | stat | File::stat::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::stat; | ||||
2 | 2 | 35µs | 1 | 12µs | # spent 12µs within File::stat::BEGIN@2 which was called:
# once (12µs+0s) by Path::Class::Entity::BEGIN@9 at line 2 # spent 12µs making 1 call to File::stat::BEGIN@2 |
3 | |||||
4 | 2 | 16µs | 2 | 21µs | # spent 13µs (5+8) within File::stat::BEGIN@4 which was called:
# once (5µs+8µs) by Path::Class::Entity::BEGIN@9 at line 4 # spent 13µs making 1 call to File::stat::BEGIN@4
# spent 8µs making 1 call to strict::import |
5 | 2 | 19µs | 2 | 12µs | # spent 9µs (5+3) within File::stat::BEGIN@5 which was called:
# once (5µs+3µs) by Path::Class::Entity::BEGIN@9 at line 5 # spent 9µs making 1 call to File::stat::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | 2 | 31µs | 2 | 189µs | # spent 98µs (7+91) within File::stat::BEGIN@6 which was called:
# once (7µs+91µs) by Path::Class::Entity::BEGIN@9 at line 6 # spent 98µs making 1 call to File::stat::BEGIN@6
# spent 91µs making 1 call to warnings::register::import |
7 | 2 | 28µs | 2 | 80µs | # spent 44µs (7+37) within File::stat::BEGIN@7 which was called:
# once (7µs+37µs) by Path::Class::Entity::BEGIN@9 at line 7 # spent 44µs making 1 call to File::stat::BEGIN@7
# spent 37µs making 1 call to Exporter::import |
8 | |||||
9 | 1 | 48µs | 1 | 3µs | # spent 3µs within File::stat::BEGIN@9 which was called:
# once (3µs+0s) by Path::Class::Entity::BEGIN@9 at line 9 # spent 3µs making 1 call to File::stat::BEGIN@9 |
10 | |||||
11 | 1 | 300ns | our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS); | ||
12 | |||||
13 | 1 | 400ns | our $VERSION = '1.07'; | ||
14 | |||||
15 | 1 | 100ns | my @fields; | ||
16 | # spent 9µs within File::stat::BEGIN@16 which was called:
# once (9µs+0s) by Path::Class::Entity::BEGIN@9 at line 27 | ||||
17 | 2 | 57µs | 1 | 3µs | # spent 3µs within File::stat::BEGIN@17 which was called:
# once (3µs+0s) by Path::Class::Entity::BEGIN@9 at line 17 # spent 3µs making 1 call to File::stat::BEGIN@17 |
18 | 1 | 1µs | @EXPORT = qw(stat lstat); | ||
19 | 1 | 2µs | @fields = qw( $st_dev $st_ino $st_mode | ||
20 | $st_nlink $st_uid $st_gid | ||||
21 | $st_rdev $st_size | ||||
22 | $st_atime $st_mtime $st_ctime | ||||
23 | $st_blksize $st_blocks | ||||
24 | ); | ||||
25 | 1 | 1µs | @EXPORT_OK = ( @fields, "stat_cando" ); | ||
26 | 1 | 5µs | %EXPORT_TAGS = ( FIELDS => [ @fields, @EXPORT ] ); | ||
27 | 1 | 18µs | 1 | 9µs | } # spent 9µs making 1 call to File::stat::BEGIN@16 |
28 | 2 | 26µs | 2 | 263µs | # spent 134µs (6+128) within File::stat::BEGIN@28 which was called:
# once (6µs+128µs) by Path::Class::Entity::BEGIN@9 at line 28 # spent 134µs making 1 call to File::stat::BEGIN@28
# spent 128µs making 1 call to vars::import |
29 | |||||
30 | 2 | 88µs | 2 | 990µs | # spent 780µs (343+437) within File::stat::BEGIN@30 which was called:
# once (343µs+437µs) by Path::Class::Entity::BEGIN@9 at line 30 # spent 780µs making 1 call to File::stat::BEGIN@30
# spent 210µs making 1 call to Exporter::import |
31 | |||||
32 | # spent 86µs (65+21) within File::stat::BEGIN@32 which was called:
# once (65µs+21µs) by Path::Class::Entity::BEGIN@9 at line 48 | ||||
33 | # These constants will croak on use if the platform doesn't define | ||||
34 | # them. It's important to avoid inflicting that on the user. | ||||
35 | 2 | 143µs | 2 | 22µs | # spent 14µs (6+8) within File::stat::BEGIN@35 which was called:
# once (6µs+8µs) by Path::Class::Entity::BEGIN@9 at line 35 # spent 14µs making 1 call to File::stat::BEGIN@35
# spent 8µs making 1 call to strict::unimport |
36 | 1 | 500ns | for (qw(suid sgid svtx)) { | ||
37 | 6 | 27µs | 3 | 8µs | my $val = eval { &{"Fcntl::S_I\U$_"} }; # spent 3µs making 1 call to Fcntl::S_ISUID
# spent 3µs making 1 call to Fcntl::S_ISGID
# spent 2µs making 1 call to Fcntl::S_ISVTX |
38 | 3 | 10µs | *{"_$_"} = defined $val ? sub { $_[0] & $val ? 1 : "" } : sub { "" }; | ||
39 | } | ||||
40 | 1 | 400ns | for (qw(SOCK CHR BLK REG DIR LNK)) { | ||
41 | 6 | 33µs | 6 | 13µs | *{"S_IS$_"} = defined eval { &{"Fcntl::S_IF$_"} } # spent 3µs making 1 call to Fcntl::S_IFSOCK
# spent 2µs making 1 call to Fcntl::S_IFLNK
# spent 2µs making 1 call to Fcntl::S_IFCHR
# spent 2µs making 1 call to Fcntl::S_IFDIR
# spent 2µs making 1 call to Fcntl::S_IFBLK
# spent 2µs making 1 call to Fcntl::S_IFREG |
42 | 6 | 12µs | ? \&{"Fcntl::S_IS$_"} : sub { "" }; | ||
43 | } | ||||
44 | # FIFO flag and macro don't quite follow the S_IF/S_IS pattern above | ||||
45 | # RT #111638 | ||||
46 | *{"S_ISFIFO"} = defined &Fcntl::S_IFIFO | ||||
47 | 1 | 5µs | ? \&Fcntl::S_ISFIFO : sub { "" }; | ||
48 | 1 | 638µs | 1 | 86µs | } # spent 86µs making 1 call to File::stat::BEGIN@32 |
49 | |||||
50 | # from doio.c | ||||
51 | sub _ingroup { | ||||
52 | my ($gid, $eff) = @_; | ||||
53 | |||||
54 | # I am assuming that since VMS doesn't have getgroups(2), $) will | ||||
55 | # always only contain a single entry. | ||||
56 | $^O eq "VMS" and return $_[0] == $); | ||||
57 | |||||
58 | my ($egid, @supp) = split " ", $); | ||||
59 | my ($rgid) = split " ", $(; | ||||
60 | |||||
61 | $gid == ($eff ? $egid : $rgid) and return 1; | ||||
62 | grep $gid == $_, @supp and return 1; | ||||
63 | |||||
64 | return ""; | ||||
65 | } | ||||
66 | |||||
67 | # VMS uses the Unix version of the routine, even though this is very | ||||
68 | # suboptimal. VMS has a permissions structure that doesn't really fit | ||||
69 | # into struct stat, and unlike on Win32 the normal -X operators respect | ||||
70 | # that, but unfortunately by the time we get here we've already lost the | ||||
71 | # information we need. It looks to me as though if we were to preserve | ||||
72 | # the st_devnam entry of vmsish.h's fake struct stat (which actually | ||||
73 | # holds the filename) it might be possible to do this right, but both | ||||
74 | # getting that value out of the struct (perl's stat doesn't return it) | ||||
75 | # and interpreting it later would require this module to have an XS | ||||
76 | # component (at which point we might as well just call Perl_cando and | ||||
77 | # have done with it). | ||||
78 | |||||
79 | 1 | 3µs | if (grep $^O eq $_, qw/os2 MSWin32 dos/) { | ||
80 | |||||
81 | # from doio.c | ||||
82 | *cando = sub { ($_[0][2] & $_[1]) ? 1 : "" }; | ||||
83 | } | ||||
84 | else { | ||||
85 | |||||
86 | # from doio.c | ||||
87 | *cando = sub { | ||||
88 | my ($s, $mode, $eff) = @_; | ||||
89 | my $uid = $eff ? $> : $<; | ||||
90 | my ($stmode, $stuid, $stgid) = @$s[2,4,5]; | ||||
91 | |||||
92 | # This code basically assumes that the rwx bits of the mode are | ||||
93 | # the 0777 bits, but so does Perl_cando. | ||||
94 | |||||
95 | if ($uid == 0 && $^O ne "VMS") { | ||||
96 | # If we're root on unix | ||||
97 | # not testing for executable status => all file tests are true | ||||
98 | return 1 if !($mode & 0111); | ||||
99 | # testing for executable status => | ||||
100 | # for a file, any x bit will do | ||||
101 | # for a directory, always true | ||||
102 | return 1 if $stmode & 0111 || S_ISDIR($stmode); | ||||
103 | return ""; | ||||
104 | } | ||||
105 | |||||
106 | if ($stuid == $uid) { | ||||
107 | $stmode & $mode and return 1; | ||||
108 | } | ||||
109 | elsif (_ingroup($stgid, $eff)) { | ||||
110 | $stmode & ($mode >> 3) and return 1; | ||||
111 | } | ||||
112 | else { | ||||
113 | $stmode & ($mode >> 6) and return 1; | ||||
114 | } | ||||
115 | return ""; | ||||
116 | 1 | 3µs | }; | ||
117 | } | ||||
118 | |||||
119 | # alias for those who don't like objects | ||||
120 | 1 | 500ns | *stat_cando = \&cando; | ||
121 | |||||
122 | my %op = ( | ||||
123 | r => sub { cando($_[0], S_IRUSR, 1) }, | ||||
124 | w => sub { cando($_[0], S_IWUSR, 1) }, | ||||
125 | x => sub { cando($_[0], S_IXUSR, 1) }, | ||||
126 | o => sub { $_[0][4] == $> }, | ||||
127 | |||||
128 | R => sub { cando($_[0], S_IRUSR, 0) }, | ||||
129 | W => sub { cando($_[0], S_IWUSR, 0) }, | ||||
130 | X => sub { cando($_[0], S_IXUSR, 0) }, | ||||
131 | O => sub { $_[0][4] == $< }, | ||||
132 | |||||
133 | e => sub { 1 }, | ||||
134 | z => sub { $_[0][7] == 0 }, | ||||
135 | s => sub { $_[0][7] }, | ||||
136 | |||||
137 | f => sub { S_ISREG ($_[0][2]) }, | ||||
138 | d => sub { S_ISDIR ($_[0][2]) }, | ||||
139 | l => sub { S_ISLNK ($_[0][2]) }, | ||||
140 | p => sub { S_ISFIFO($_[0][2]) }, | ||||
141 | S => sub { S_ISSOCK($_[0][2]) }, | ||||
142 | b => sub { S_ISBLK ($_[0][2]) }, | ||||
143 | c => sub { S_ISCHR ($_[0][2]) }, | ||||
144 | |||||
145 | u => sub { _suid($_[0][2]) }, | ||||
146 | g => sub { _sgid($_[0][2]) }, | ||||
147 | k => sub { _svtx($_[0][2]) }, | ||||
148 | |||||
149 | M => sub { ($^T - $_[0][9] ) / 86400 }, | ||||
150 | C => sub { ($^T - $_[0][10]) / 86400 }, | ||||
151 | A => sub { ($^T - $_[0][8] ) / 86400 }, | ||||
152 | 1 | 32µs | ); | ||
153 | |||||
154 | 2 | 115µs | 2 | 81µs | # spent 44µs (7+37) within File::stat::BEGIN@154 which was called:
# once (7µs+37µs) by Path::Class::Entity::BEGIN@9 at line 154 # spent 44µs making 1 call to File::stat::BEGIN@154
# spent 37µs making 1 call to constant::import |
155 | |||||
156 | # we need fallback=>1 or stringifying breaks | ||||
157 | use overload | ||||
158 | # spent 42µs (10+32) within File::stat::BEGIN@158 which was called:
# once (10µs+32µs) by Path::Class::Entity::BEGIN@9 at line 179 | ||||
159 | -X => sub { | ||||
160 | my ($s, $op) = @_; | ||||
161 | |||||
162 | if (index("rwxRWX", $op) >= 0) { | ||||
163 | (caller 0)[8] & HINT_FILETEST_ACCESS | ||||
164 | and warnif("File::stat ignores use filetest 'access'"); | ||||
165 | |||||
166 | $^O eq "VMS" and warnif("File::stat ignores VMS ACLs"); | ||||
167 | |||||
168 | # It would be nice to have a warning about using -l on a | ||||
169 | # non-lstat, but that would require an extra member in the | ||||
170 | # object. | ||||
171 | } | ||||
172 | |||||
173 | if ($op{$op}) { | ||||
174 | return $op{$op}->($_[0]); | ||||
175 | } | ||||
176 | else { | ||||
177 | croak "-$op is not implemented on a File::stat object"; | ||||
178 | } | ||||
179 | 2 | 42µs | 2 | 73µs | }; # spent 42µs making 1 call to File::stat::BEGIN@158
# spent 32µs making 1 call to overload::import |
180 | |||||
181 | # Class::Struct forbids use of @ISA | ||||
182 | 1 | 11µs | 1 | 40µs | # spent 6µs within File::stat::import which was called:
# once (6µs+0s) by IO::Dir::BEGIN@18 at line 18 of IO/Dir.pm # spent 40µs making 1 call to Exporter::import |
183 | |||||
184 | 2 | 221µs | 2 | 12.0ms | # spent 6.68ms (1.13+5.55) within File::stat::BEGIN@184 which was called:
# once (1.13ms+5.55ms) by Path::Class::Entity::BEGIN@9 at line 184 # spent 6.68ms making 1 call to File::stat::BEGIN@184
# spent 5.36ms making 1 call to Class::Struct::import |
185 | struct 'File::stat' => [ | ||||
186 | 1 | 10µs | 1 | 800µs | map { $_ => '$' } qw{ # spent 800µs making 1 call to Class::Struct::struct |
187 | dev ino mode nlink uid gid rdev size | ||||
188 | atime mtime ctime blksize blocks | ||||
189 | } | ||||
190 | ]; | ||||
191 | |||||
192 | sub populate (@) { | ||||
193 | return unless @_; | ||||
194 | my $stob = new(); | ||||
195 | @$stob = ( | ||||
196 | $st_dev, $st_ino, $st_mode, $st_nlink, $st_uid, $st_gid, $st_rdev, | ||||
197 | $st_size, $st_atime, $st_mtime, $st_ctime, $st_blksize, $st_blocks ) | ||||
198 | = @_; | ||||
199 | return $stob; | ||||
200 | } | ||||
201 | |||||
202 | sub lstat ($) { populate(CORE::lstat(shift)) } | ||||
203 | |||||
204 | sub stat ($) { | ||||
205 | my $arg = shift; | ||||
206 | my $st = populate(CORE::stat $arg); | ||||
207 | return $st if defined $st; | ||||
208 | my $fh; | ||||
209 | { | ||||
210 | local $!; | ||||
211 | 2 | 88µs | 2 | 27µs | # spent 17µs (7+10) within File::stat::BEGIN@211 which was called:
# once (7µs+10µs) by Path::Class::Entity::BEGIN@9 at line 211 # spent 17µs making 1 call to File::stat::BEGIN@211
# spent 10µs making 1 call to strict::unimport |
212 | require Symbol; | ||||
213 | $fh = \*{ Symbol::qualify( $arg, caller() )}; | ||||
214 | return unless defined fileno $fh; | ||||
215 | } | ||||
216 | return populate(CORE::stat $fh); | ||||
217 | } | ||||
218 | |||||
219 | 1 | 12µs | 1; | ||
220 | __END__ |