| Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/DirHandle.pm |
| Statements | Executed 70 statements in 7.79ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 4 | 1 | 1 | 6.96ms | 6.96ms | DirHandle::CORE:readdir (opcode) |
| 5 | 1 | 1 | 283µs | 283µs | DirHandle::CORE:open_dir (opcode) |
| 5 | 5 | 2 | 199µs | 242µs | DirHandle::DESTROY |
| 5 | 5 | 2 | 118µs | 619µs | DirHandle::new |
| 4 | 4 | 2 | 62µs | 7.02ms | DirHandle::read |
| 5 | 1 | 1 | 61µs | 344µs | DirHandle::open |
| 6 | 2 | 1 | 54µs | 54µs | DirHandle::CORE:closedir (opcode) |
| 1 | 1 | 1 | 17µs | 28µs | DirHandle::close |
| 0 | 0 | 0 | 0s | 0s | DirHandle::BEGIN |
| 0 | 0 | 0 | 0s | 0s | DirHandle::rewind |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DirHandle; | ||||
| 2 | |||||
| 3 | our $VERSION = '1.04'; | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | DirHandle - supply object methods for directory handles | ||||
| 8 | |||||
| 9 | =head1 SYNOPSIS | ||||
| 10 | |||||
| 11 | use DirHandle; | ||||
| 12 | $d = DirHandle->new("."); | ||||
| 13 | if (defined $d) { | ||||
| 14 | while (defined($_ = $d->read)) { something($_); } | ||||
| 15 | $d->rewind; | ||||
| 16 | while (defined($_ = $d->read)) { something_else($_); } | ||||
| 17 | undef $d; | ||||
| 18 | } | ||||
| 19 | |||||
| 20 | =head1 DESCRIPTION | ||||
| 21 | |||||
| 22 | The C<DirHandle> method provide an alternative interface to the | ||||
| 23 | opendir(), closedir(), readdir(), and rewinddir() functions. | ||||
| 24 | |||||
| 25 | The only objective benefit to using C<DirHandle> is that it avoids | ||||
| 26 | namespace pollution by creating globs to hold directory handles. | ||||
| 27 | |||||
| 28 | =cut | ||||
| 29 | |||||
| 30 | require 5.000; | ||||
| 31 | use Carp; | ||||
| 32 | use Symbol; | ||||
| 33 | |||||
| 34 | # spent 619µs (118+501) within DirHandle::new which was called 5 times, avg 124µs/call:
# once (27µs+194µs) by CPAN::Distribution::run_preps_on_packagedir at line 513 of CPAN/Distribution.pm
# once (29µs+145µs) by CPAN::CacheMgr::entries at line 68 of CPAN/CacheMgr.pm
# once (28µs+78µs) by CPAN::Distribution::_find_prefs at line 2398 of CPAN/Distribution.pm
# once (18µs+47µs) by CPAN::Distribution::run_preps_on_packagedir at line 533 of CPAN/Distribution.pm
# once (16µs+37µs) by CPAN::CacheMgr::new at line 207 of CPAN/CacheMgr.pm | ||||
| 35 | 5 | 17µs | @_ >= 1 && @_ <= 2 or croak 'usage: DirHandle->new( [DIRNAME] )'; | ||
| 36 | 5 | 11µs | my $class = shift; | ||
| 37 | 5 | 14µs | 5 | 157µs | my $dh = gensym; # spent 157µs making 5 calls to Symbol::gensym, avg 31µs/call |
| 38 | 5 | 23µs | 5 | 344µs | if (@_) { # spent 344µs making 5 calls to DirHandle::open, avg 69µs/call |
| 39 | DirHandle::open($dh, $_[0]) | ||||
| 40 | or return undef; | ||||
| 41 | } | ||||
| 42 | 5 | 44µs | bless $dh, $class; | ||
| 43 | } | ||||
| 44 | |||||
| 45 | # spent 242µs (199+43) within DirHandle::DESTROY which was called 5 times, avg 48µs/call:
# once (59µs+6µs) by CPAN::Distribution::run_preps_on_packagedir at line 546 of CPAN/Distribution.pm
# once (40µs+15µs) by CPAN::CacheMgr::new at line 214 of CPAN/CacheMgr.pm
# once (34µs+14µs) by CPAN::Distribution::_find_prefs at line 2400 of CPAN/Distribution.pm
# once (41µs+7µs) by CPAN::CacheMgr::entries at line 82 of CPAN/CacheMgr.pm
# once (25µs+1000ns) by CPAN::Distribution::run_preps_on_packagedir at line 596 of CPAN/Distribution.pm | ||||
| 46 | 5 | 3µs | my ($dh) = @_; | ||
| 47 | # Don't warn about already being closed as it may have been closed | ||||
| 48 | # correctly, or maybe never opened at all. | ||||
| 49 | 5 | 134µs | local($., $@, $!, $^E, $?); | ||
| 50 | no warnings 'io'; | ||||
| 51 | 5 | 124µs | 5 | 43µs | closedir($dh); # spent 43µs making 5 calls to DirHandle::CORE:closedir, avg 9µs/call |
| 52 | } | ||||
| 53 | |||||
| 54 | # spent 344µs (61+283) within DirHandle::open which was called 5 times, avg 69µs/call:
# 5 times (61µs+283µs) by DirHandle::new at line 38, avg 69µs/call | ||||
| 55 | 5 | 3µs | @_ == 2 or croak 'usage: $dh->open(DIRNAME)'; | ||
| 56 | 5 | 5µs | my ($dh, $dirname) = @_; | ||
| 57 | 5 | 336µs | 5 | 283µs | opendir($dh, $dirname); # spent 283µs making 5 calls to DirHandle::CORE:open_dir, avg 57µs/call |
| 58 | } | ||||
| 59 | |||||
| 60 | # spent 28µs (17+11) within DirHandle::close which was called:
# once (17µs+11µs) by CPAN::Distribution::run_preps_on_packagedir at line 525 of CPAN/Distribution.pm | ||||
| 61 | 1 | 1µs | @_ == 1 or croak 'usage: $dh->close()'; | ||
| 62 | 1 | 0s | my ($dh) = @_; | ||
| 63 | 1 | 38µs | 1 | 11µs | closedir($dh); # spent 11µs making 1 call to DirHandle::CORE:closedir |
| 64 | } | ||||
| 65 | |||||
| 66 | # spent 7.02ms (62µs+6.95) within DirHandle::read which was called 4 times, avg 1.75ms/call:
# once (35µs+6.83ms) by CPAN::CacheMgr::entries at line 71 of CPAN/CacheMgr.pm
# once (7µs+73µs) by CPAN::Distribution::run_preps_on_packagedir at line 546 of CPAN/Distribution.pm
# once (9µs+28µs) by CPAN::Distribution::run_preps_on_packagedir at line 515 of CPAN/Distribution.pm
# once (11µs+25µs) by CPAN::Distribution::_find_prefs at line 2399 of CPAN/Distribution.pm | ||||
| 67 | 4 | 2µs | @_ == 1 or croak 'usage: $dh->read()'; | ||
| 68 | 4 | 1µs | my ($dh) = @_; | ||
| 69 | 4 | 7.04ms | 4 | 6.96ms | readdir($dh); # spent 6.96ms making 4 calls to DirHandle::CORE:readdir, avg 1.74ms/call |
| 70 | } | ||||
| 71 | |||||
| 72 | sub rewind { | ||||
| 73 | @_ == 1 or croak 'usage: $dh->rewind()'; | ||||
| 74 | my ($dh) = @_; | ||||
| 75 | rewinddir($dh); | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | 1; | ||||
sub DirHandle::CORE:closedir; # opcode | |||||
# spent 283µs within DirHandle::CORE:open_dir which was called 5 times, avg 57µs/call:
# 5 times (283µs+0s) by DirHandle::open at line 57, avg 57µs/call | |||||
# spent 6.96ms within DirHandle::CORE:readdir which was called 4 times, avg 1.74ms/call:
# 4 times (6.96ms+0s) by DirHandle::read at line 69, avg 1.74ms/call |