Filename | /usr/local/lib/perl5/5.24/SelectSaver.pm |
Statements | Executed 56 statements in 889µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
7 | 1 | 1 | 309µs | 464µs | new | SelectSaver::
7 | 1 | 1 | 109µs | 127µs | DESTROY | SelectSaver::
21 | 3 | 1 | 106µs | 106µs | CORE:select (opcode) | SelectSaver::
1 | 1 | 1 | 51µs | 263µs | BEGIN@38 | SelectSaver::
1 | 1 | 1 | 19µs | 198µ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 | 18µs | require 5.000; | ||
38 | 2 | 85µs | 2 | 474µs | # spent 263µs (51+212) within SelectSaver::BEGIN@38 which was called:
# once (51µs+212µs) by IO::Handle::BEGIN@268 at line 38 # spent 263µs making 1 call to SelectSaver::BEGIN@38
# spent 212µs making 1 call to Exporter::import |
39 | 2 | 255µs | 2 | 376µs | # spent 198µs (19+179) within SelectSaver::BEGIN@39 which was called:
# once (19µs+179µs) by IO::Handle::BEGIN@268 at line 39 # spent 198µs making 1 call to SelectSaver::BEGIN@39
# spent 179µs making 1 call to Exporter::import |
40 | |||||
41 | # spent 464µs (309+155) within SelectSaver::new which was called 7 times, avg 66µs/call:
# 7 times (309µs+155µs) by IO::Handle::autoflush at line 497 of IO/Handle.pm, avg 66µs/call | ||||
42 | 7 | 31µs | @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )'; | ||
43 | 7 | 117µs | 7 | 42µs | my $fh = select; # spent 42µs making 7 calls to SelectSaver::CORE:select, avg 6µs/call |
44 | 7 | 29µs | my $self = bless \$fh, $_[0]; | ||
45 | 7 | 154µs | 14 | 113µs | select qualify($_[1], caller) if @_ > 1; # spent 67µs making 7 calls to Symbol::qualify, avg 10µs/call
# spent 46µs making 7 calls to SelectSaver::CORE:select, avg 7µs/call |
46 | 7 | 52µs | $self; | ||
47 | } | ||||
48 | |||||
49 | # spent 127µs (109+18) within SelectSaver::DESTROY which was called 7 times, avg 18µs/call:
# 7 times (109µs+18µs) by IO::Handle::autoflush at line 500 of IO/Handle.pm, avg 18µs/call | ||||
50 | 7 | 15µs | my $self = $_[0]; | ||
51 | 7 | 119µs | 7 | 18µs | select $$self; # spent 18µs making 7 calls to SelectSaver::CORE:select, avg 3µs/call |
52 | } | ||||
53 | |||||
54 | 1 | 13µs | 1; | ||
sub SelectSaver::CORE:select; # opcode |