| Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/SelectSaver.pm |
| Statements | Executed 7 statements in 40µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 21µs | 27µs | SelectSaver::new |
| 1 | 1 | 1 | 9µs | 10µs | SelectSaver::DESTROY |
| 3 | 3 | 1 | 5µs | 5µs | SelectSaver::CORE:select (opcode) |
| 0 | 0 | 0 | 0s | 0s | SelectSaver::BEGIN |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package SelectSaver; | ||||
| 2 | |||||
| 3 | our $VERSION = '1.02'; | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | SelectSaver - save and restore selected file handle | ||||
| 8 | |||||
| 9 | =head1 SYNOPSIS | ||||
| 10 | |||||
| 11 | use SelectSaver; | ||||
| 12 | |||||
| 13 | { | ||||
| 14 | my $saver = SelectSaver->new(FILEHANDLE); | ||||
| 15 | # FILEHANDLE is selected | ||||
| 16 | } | ||||
| 17 | # previous handle is selected | ||||
| 18 | |||||
| 19 | { | ||||
| 20 | my $saver = SelectSaver->new; | ||||
| 21 | # new handle may be selected, or not | ||||
| 22 | } | ||||
| 23 | # previous handle is selected | ||||
| 24 | |||||
| 25 | =head1 DESCRIPTION | ||||
| 26 | |||||
| 27 | A C<SelectSaver> object contains a reference to the file handle that | ||||
| 28 | was selected when it was created. If its C<new> method gets an extra | ||||
| 29 | parameter, then that parameter is selected; otherwise, the selected | ||||
| 30 | file handle remains unchanged. | ||||
| 31 | |||||
| 32 | When a C<SelectSaver> is destroyed, it re-selects the file handle | ||||
| 33 | that was selected when it was created. | ||||
| 34 | |||||
| 35 | =cut | ||||
| 36 | |||||
| 37 | require 5.000; | ||||
| 38 | use Carp; | ||||
| 39 | use Symbol; | ||||
| 40 | |||||
| 41 | # spent 27µs (21+6) within SelectSaver::new which was called:
# once (21µs+6µs) by IO::Handle::autoflush at line 497 of IO/Handle.pm | ||||
| 42 | 1 | 2µs | @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )'; | ||
| 43 | 1 | 9µs | 1 | 2µs | my $fh = select; # spent 2µs making 1 call to SelectSaver::CORE:select |
| 44 | 1 | 1µs | my $self = bless \$fh, $_[0]; | ||
| 45 | 1 | 6µs | 2 | 4µs | select qualify($_[1], caller) if @_ > 1; # spent 2µs making 1 call to SelectSaver::CORE:select
# spent 2µs making 1 call to Symbol::qualify |
| 46 | 1 | 8µs | $self; | ||
| 47 | } | ||||
| 48 | |||||
| 49 | # spent 10µs (9+1) within SelectSaver::DESTROY which was called:
# once (9µs+1µs) by IO::Handle::autoflush at line 500 of IO/Handle.pm | ||||
| 50 | 1 | 1µs | my $self = $_[0]; | ||
| 51 | 1 | 13µs | 1 | 1µs | select $$self; # spent 1µs making 1 call to SelectSaver::CORE:select |
| 52 | } | ||||
| 53 | |||||
| 54 | 1; | ||||
sub SelectSaver::CORE:select; # opcode |