Filename | /usr/local/lib/perl5/5.24/SelectSaver.pm |
Statements | Executed 70 statements in 1.05ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
9 | 1 | 1 | 447µs | 660µs | new | SelectSaver::
9 | 1 | 1 | 139µs | 165µs | DESTROY | SelectSaver::
27 | 3 | 1 | 136µs | 136µs | CORE:select (opcode) | SelectSaver::
1 | 1 | 1 | 44µs | 276µs | BEGIN@38 | SelectSaver::
1 | 1 | 1 | 23µs | 199µs | BEGIN@39 | SelectSaver::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package SelectSaver; | ||||
2 | |||||
3 | 1 | 2µs | 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 | 1 | 32µs | require 5.000; | ||
38 | 2 | 81µs | 2 | 507µs | # spent 276µs (44+232) within SelectSaver::BEGIN@38 which was called:
# once (44µs+232µs) by IO::Handle::BEGIN@268 at line 38 # spent 276µs making 1 call to SelectSaver::BEGIN@38
# spent 232µs making 1 call to Exporter::import |
39 | 2 | 240µs | 2 | 376µs | # spent 199µs (23+177) within SelectSaver::BEGIN@39 which was called:
# once (23µs+177µs) by IO::Handle::BEGIN@268 at line 39 # spent 199µs making 1 call to SelectSaver::BEGIN@39
# spent 177µs making 1 call to Exporter::import |
40 | |||||
41 | # spent 660µs (447+213) within SelectSaver::new which was called 9 times, avg 73µs/call:
# 9 times (447µs+213µs) by IO::Handle::autoflush at line 497 of IO/Handle.pm, avg 73µs/call | ||||
42 | 9 | 48µs | @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )'; | ||
43 | 9 | 158µs | 9 | 57µs | my $fh = select; # spent 57µs making 9 calls to SelectSaver::CORE:select, avg 6µs/call |
44 | 9 | 38µs | my $self = bless \$fh, $_[0]; | ||
45 | 9 | 197µs | 18 | 156µs | select qualify($_[1], caller) if @_ > 1; # spent 103µs making 9 calls to Symbol::qualify, avg 11µs/call
# spent 53µs making 9 calls to SelectSaver::CORE:select, avg 6µs/call |
46 | 9 | 68µs | $self; | ||
47 | } | ||||
48 | |||||
49 | # spent 165µs (139+26) within SelectSaver::DESTROY which was called 9 times, avg 18µs/call:
# 9 times (139µs+26µs) by IO::Handle::autoflush at line 500 of IO/Handle.pm, avg 18µs/call | ||||
50 | 9 | 19µs | my $self = $_[0]; | ||
51 | 9 | 158µs | 9 | 26µs | select $$self; # spent 26µs making 9 calls to SelectSaver::CORE:select, avg 3µs/call |
52 | } | ||||
53 | |||||
54 | 1 | 7µs | 1; | ||
sub SelectSaver::CORE:select; # opcode |