| File | /usr/lib/perl5/5.10.1/File/stat.pm |
| Statements Executed | 32 |
| Statement Execution Time | 2.59ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 6.54ms | 8.54ms | File::stat::BEGIN@27 |
| 1 | 1 | 1 | 84µs | 84µs | File::stat::BEGIN@2 |
| 1 | 1 | 1 | 68µs | 133µs | File::stat::BEGIN@5 |
| 1 | 1 | 1 | 41µs | 41µs | File::stat::BEGIN@11 |
| 1 | 1 | 1 | 31µs | 737µs | File::stat::BEGIN@22 |
| 1 | 1 | 1 | 30µs | 77µs | File::stat::BEGIN@54 |
| 3 | 3 | 3 | 29µs | 29µs | File::stat::import |
| 1 | 1 | 1 | 28µs | 40µs | File::stat::BEGIN@4 |
| 1 | 1 | 1 | 18µs | 18µs | File::stat::BEGIN@12 |
| 0 | 0 | 0 | 0s | 0s | File::stat::lstat |
| 0 | 0 | 0 | 0s | 0s | File::stat::populate |
| 0 | 0 | 0 | 0s | 0s | File::stat::stat |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package File::stat; | ||||
| 2 | 3 | 127µs | 1 | 84µs | # spent 84µs within File::stat::BEGIN@2 which was called
# once (84µs+0s) by Path::Class::Entity::BEGIN@7 at line 2 # spent 84µs making 1 call to File::stat::BEGIN@2 |
| 3 | |||||
| 4 | 3 | 74µs | 2 | 51µs | # spent 40µs (28+11) within File::stat::BEGIN@4 which was called
# once (28µs+11µs) by Path::Class::Entity::BEGIN@7 at line 4 # spent 40µs making 1 call to File::stat::BEGIN@4
# spent 11µs making 1 call to strict::import |
| 5 | 3 | 234µs | 2 | 198µs | # spent 133µs (68+65) within File::stat::BEGIN@5 which was called
# once (68µs+65µs) by Path::Class::Entity::BEGIN@7 at line 5 # spent 133µs making 1 call to File::stat::BEGIN@5
# spent 65µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 1 | 2µs | our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS); | ||
| 8 | |||||
| 9 | 1 | 3µs | our $VERSION = '1.01'; | ||
| 10 | |||||
| 11 | # spent 41µs within File::stat::BEGIN@11 which was called
# once (41µs+0s) by Path::Class::Entity::BEGIN@7 at line 21 | ||||
| 12 | 3 | 219µs | 1 | 18µs | # spent 18µs within File::stat::BEGIN@12 which was called
# once (18µs+0s) by Path::Class::Entity::BEGIN@7 at line 12 # spent 18µs making 1 call to File::stat::BEGIN@12 |
| 13 | 1 | 5µs | @EXPORT = qw(stat lstat); | ||
| 14 | 1 | 10µs | @EXPORT_OK = qw( $st_dev $st_ino $st_mode | ||
| 15 | $st_nlink $st_uid $st_gid | ||||
| 16 | $st_rdev $st_size | ||||
| 17 | $st_atime $st_mtime $st_ctime | ||||
| 18 | $st_blksize $st_blocks | ||||
| 19 | ); | ||||
| 20 | 1 | 27µs | %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] ); | ||
| 21 | 1 | 83µs | 1 | 41µs | } # spent 41µs making 1 call to File::stat::BEGIN@11 |
| 22 | 3 | 145µs | 2 | 1.44ms | # spent 737µs (31+706) within File::stat::BEGIN@22 which was called
# once (31µs+706µs) by Path::Class::Entity::BEGIN@7 at line 22 # spent 737µs making 1 call to File::stat::BEGIN@22
# spent 706µs making 1 call to vars::import |
| 23 | |||||
| 24 | # Class::Struct forbids use of @ISA | ||||
| 25 | 3 | 292µs | 3 | 493µs | # spent 29µs within File::stat::import which was called 3 times, avg 10µs/call:
# once (11µs+0s) by Catalyst::Plugin::Static::Simple::BEGIN@4 at line 4 of Catalyst/Plugin/Static/Simple.pm
# once (10µs+0s) by IO::Dir::BEGIN@18 at line 18 of IO/Dir.pm
# once (8µs+0s) by Catalyst::BEGIN@18 at line 18 of Catalyst.pm # spent 493µs making 3 calls to Exporter::import, avg 164µs/call |
| 26 | |||||
| 27 | 3 | 1.11ms | 2 | 9.27ms | # spent 8.54ms (6.54+2.00) within File::stat::BEGIN@27 which was called
# once (6.54ms+2.00ms) by Path::Class::Entity::BEGIN@7 at line 27 # spent 8.54ms making 1 call to File::stat::BEGIN@27
# spent 728µs making 1 call to Class::Struct::import |
| 28 | struct 'File::stat' => [ | ||||
| 29 | 1 | 48µs | 1 | 4.87ms | map { $_ => '$' } qw{ # spent 4.87ms making 1 call to Class::Struct::struct |
| 30 | dev ino mode nlink uid gid rdev size | ||||
| 31 | atime mtime ctime blksize blocks | ||||
| 32 | } | ||||
| 33 | ]; | ||||
| 34 | |||||
| 35 | sub populate (@) { | ||||
| 36 | return unless @_; | ||||
| 37 | my $stob = new(); | ||||
| 38 | @$stob = ( | ||||
| 39 | $st_dev, $st_ino, $st_mode, $st_nlink, $st_uid, $st_gid, $st_rdev, | ||||
| 40 | $st_size, $st_atime, $st_mtime, $st_ctime, $st_blksize, $st_blocks ) | ||||
| 41 | = @_; | ||||
| 42 | return $stob; | ||||
| 43 | } | ||||
| 44 | |||||
| 45 | sub lstat ($) { populate(CORE::lstat(shift)) } | ||||
| 46 | |||||
| 47 | sub stat ($) { | ||||
| 48 | my $arg = shift; | ||||
| 49 | my $st = populate(CORE::stat $arg); | ||||
| 50 | return $st if $st; | ||||
| 51 | my $fh; | ||||
| 52 | { | ||||
| 53 | local $!; | ||||
| 54 | 3 | 186µs | 2 | 124µs | # spent 77µs (30+47) within File::stat::BEGIN@54 which was called
# once (30µs+47µs) by Path::Class::Entity::BEGIN@7 at line 54 # spent 77µs making 1 call to File::stat::BEGIN@54
# spent 47µs making 1 call to strict::unimport |
| 55 | require Symbol; | ||||
| 56 | $fh = \*{ Symbol::qualify( $arg, caller() )}; | ||||
| 57 | return unless defined fileno $fh; | ||||
| 58 | } | ||||
| 59 | return populate(CORE::stat $fh); | ||||
| 60 | } | ||||
| 61 | |||||
| 62 | 1 | 24µs | 1; | ||
| 63 | __END__ | ||||
| 64 | |||||
| 65 | =head1 NAME | ||||
| 66 | |||||
| 67 | File::stat - by-name interface to Perl's built-in stat() functions | ||||
| 68 | |||||
| 69 | =head1 SYNOPSIS | ||||
| 70 | |||||
| 71 | use File::stat; | ||||
| 72 | $st = stat($file) or die "No $file: $!"; | ||||
| 73 | if ( ($st->mode & 0111) && $st->nlink > 1) ) { | ||||
| 74 | print "$file is executable with lotsa links\n"; | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | use File::stat qw(:FIELDS); | ||||
| 78 | stat($file) or die "No $file: $!"; | ||||
| 79 | if ( ($st_mode & 0111) && ($st_nlink > 1) ) { | ||||
| 80 | print "$file is executable with lotsa links\n"; | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | =head1 DESCRIPTION | ||||
| 84 | |||||
| 85 | This module's default exports override the core stat() | ||||
| 86 | and lstat() functions, replacing them with versions that return | ||||
| 87 | "File::stat" objects. This object has methods that | ||||
| 88 | return the similarly named structure field name from the | ||||
| 89 | stat(2) function; namely, | ||||
| 90 | dev, | ||||
| 91 | ino, | ||||
| 92 | mode, | ||||
| 93 | nlink, | ||||
| 94 | uid, | ||||
| 95 | gid, | ||||
| 96 | rdev, | ||||
| 97 | size, | ||||
| 98 | atime, | ||||
| 99 | mtime, | ||||
| 100 | ctime, | ||||
| 101 | blksize, | ||||
| 102 | and | ||||
| 103 | blocks. | ||||
| 104 | |||||
| 105 | You may also import all the structure fields directly into your namespace | ||||
| 106 | as regular variables using the :FIELDS import tag. (Note that this still | ||||
| 107 | overrides your stat() and lstat() functions.) Access these fields as | ||||
| 108 | variables named with a preceding C<st_> in front their method names. | ||||
| 109 | Thus, C<$stat_obj-E<gt>dev()> corresponds to $st_dev if you import | ||||
| 110 | the fields. | ||||
| 111 | |||||
| 112 | To access this functionality without the core overrides, | ||||
| 113 | pass the C<use> an empty import list, and then access | ||||
| 114 | function functions with their full qualified names. | ||||
| 115 | On the other hand, the built-ins are still available | ||||
| 116 | via the C<CORE::> pseudo-package. | ||||
| 117 | |||||
| 118 | =head1 BUGS | ||||
| 119 | |||||
| 120 | As of Perl 5.8.0 after using this module you cannot use the implicit | ||||
| 121 | C<$_> or the special filehandle C<_> with stat() or lstat(), trying | ||||
| 122 | to do so leads into strange errors. The workaround is for C<$_> to | ||||
| 123 | be explicit | ||||
| 124 | |||||
| 125 | my $stat_obj = stat $_; | ||||
| 126 | |||||
| 127 | and for C<_> to explicitly populate the object using the unexported | ||||
| 128 | and undocumented populate() function with CORE::stat(): | ||||
| 129 | |||||
| 130 | my $stat_obj = File::stat::populate(CORE::stat(_)); | ||||
| 131 | |||||
| 132 | =head1 NOTE | ||||
| 133 | |||||
| 134 | While this class is currently implemented using the Class::Struct | ||||
| 135 | module to build a struct-like class, you shouldn't rely upon this. | ||||
| 136 | |||||
| 137 | =head1 AUTHOR | ||||
| 138 | |||||
| 139 | Tom Christiansen |