| Filename | /usr/lib64/perl5/vendor_perl/5.16.0/IO/WrapTie.pm |
| Statements | Executed 31 statements in 4.96ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.98ms | 1.98ms | IO::WrapTie::Master::PRELOAD |
| 1 | 1 | 1 | 84µs | 192µs | IO::WrapTie::BEGIN@8 |
| 1 | 1 | 1 | 56µs | 147µs | IO::WrapTie::Master::BEGIN@34 |
| 1 | 1 | 1 | 55µs | 161µs | IO::WrapTie::BEGIN@10 |
| 1 | 1 | 1 | 54µs | 154µs | IO::WrapTie::Master::BEGIN@36 |
| 1 | 1 | 1 | 50µs | 352µs | IO::WrapTie::BEGIN@9 |
| 1 | 1 | 1 | 49µs | 266µs | IO::WrapTie::Master::BEGIN@35 |
| 0 | 0 | 0 | 0s | 0s | IO::WrapTie::Master::AUTOLOAD |
| 0 | 0 | 0 | 0s | 0s | IO::WrapTie::Master::new |
| 0 | 0 | 0 | 0s | 0s | IO::WrapTie::Slave::TIE_MASTER |
| 0 | 0 | 0 | 0s | 0s | IO::WrapTie::Slave::new_tie |
| 0 | 0 | 0 | 0s | 0s | IO::WrapTie::new |
| 0 | 0 | 0 | 0s | 0s | IO::WrapTie::wraptie |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # SEE DOCUMENTATION AT BOTTOM OF FILE | ||||
| 2 | |||||
| 3 | |||||
| 4 | #------------------------------------------------------------ | ||||
| 5 | package IO::WrapTie; | ||||
| 6 | #------------------------------------------------------------ | ||||
| 7 | 1 | 62µs | require 5.004; ### for tie | ||
| 8 | 2 | 174µs | 2 | 299µs | # spent 192µs (84+108) within IO::WrapTie::BEGIN@8 which was called:
# once (84µs+108µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 8 # spent 192µs making 1 call to IO::WrapTie::BEGIN@8
# spent 108µs making 1 call to strict::import |
| 9 | 2 | 150µs | 2 | 654µs | # spent 352µs (50+302) within IO::WrapTie::BEGIN@9 which was called:
# once (50µs+302µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 9 # spent 352µs making 1 call to IO::WrapTie::BEGIN@9
# spent 302µs making 1 call to vars::import |
| 10 | 2 | 684µs | 2 | 267µs | # spent 161µs (55+106) within IO::WrapTie::BEGIN@10 which was called:
# once (55µs+106µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 10 # spent 161µs making 1 call to IO::WrapTie::BEGIN@10
# spent 106µs making 1 call to Exporter::import |
| 11 | |||||
| 12 | # Inheritance, exporting, and package version: | ||||
| 13 | 1 | 34µs | @ISA = qw(Exporter); | ||
| 14 | 1 | 6µs | @EXPORT = qw(wraptie); | ||
| 15 | 1 | 2µs | $VERSION = "2.110"; | ||
| 16 | |||||
| 17 | # Function, exported. | ||||
| 18 | sub wraptie { | ||||
| 19 | IO::WrapTie::Master->new(@_); | ||||
| 20 | } | ||||
| 21 | |||||
| 22 | # Class method; BACKWARDS-COMPATIBILITY ONLY! | ||||
| 23 | sub new { | ||||
| 24 | shift; | ||||
| 25 | IO::WrapTie::Master->new(@_); | ||||
| 26 | } | ||||
| 27 | |||||
| - - | |||||
| 30 | #------------------------------------------------------------ | ||||
| 31 | package IO::WrapTie::Master; | ||||
| 32 | #------------------------------------------------------------ | ||||
| 33 | |||||
| 34 | 2 | 156µs | 2 | 237µs | # spent 147µs (56+90) within IO::WrapTie::Master::BEGIN@34 which was called:
# once (56µs+90µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 34 # spent 147µs making 1 call to IO::WrapTie::Master::BEGIN@34
# spent 90µs making 1 call to strict::import |
| 35 | 2 | 160µs | 2 | 482µs | # spent 266µs (49+217) within IO::WrapTie::Master::BEGIN@35 which was called:
# once (49µs+217µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 35 # spent 266µs making 1 call to IO::WrapTie::Master::BEGIN@35
# spent 217µs making 1 call to vars::import |
| 36 | 2 | 1.45ms | 2 | 254µs | # spent 154µs (54+100) within IO::WrapTie::Master::BEGIN@36 which was called:
# once (54µs+100µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 36 # spent 154µs making 1 call to IO::WrapTie::Master::BEGIN@36
# spent 100µs making 1 call to Exporter::import |
| 37 | |||||
| 38 | # We inherit from IO::Handle to get methods which invoke i/o operators, | ||||
| 39 | # like print(), on our tied handle: | ||||
| 40 | 1 | 26µs | @ISA = qw(IO::Handle); | ||
| 41 | |||||
| 42 | #------------------------------ | ||||
| 43 | # new SLAVE, TIEARGS... | ||||
| 44 | #------------------------------ | ||||
| 45 | # Create a new subclass of IO::Handle which... | ||||
| 46 | # | ||||
| 47 | # (1) Handles i/o OPERATORS because it is tied to an instance of | ||||
| 48 | # an i/o-like class, like IO::Scalar. | ||||
| 49 | # | ||||
| 50 | # (2) Handles i/o METHODS by delegating them to that same tied object!. | ||||
| 51 | # | ||||
| 52 | # Arguments are the slave class (e.g., IO::Scalar), followed by all | ||||
| 53 | # the arguments normally sent into that class's TIEHANDLE method. | ||||
| 54 | # In other words, much like the arguments to tie(). :-) | ||||
| 55 | # | ||||
| 56 | # NOTE: | ||||
| 57 | # The thing $x we return must be a BLESSED REF, for ($x->print()). | ||||
| 58 | # The underlying symbol must be a FILEHANDLE, for (print $x "foo"). | ||||
| 59 | # It has to have a way of getting to the "real" back-end object... | ||||
| 60 | # | ||||
| 61 | sub new { | ||||
| 62 | my $master = shift; | ||||
| 63 | my $io = IO::Handle->new; ### create a new handle | ||||
| 64 | my $slave = shift; | ||||
| 65 | tie *$io, $slave, @_; ### tie: will invoke slave's TIEHANDLE | ||||
| 66 | bless $io, $master; ### return a master | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | #------------------------------ | ||||
| 70 | # AUTOLOAD | ||||
| 71 | #------------------------------ | ||||
| 72 | # Delegate method invocations on the master to the underlying slave. | ||||
| 73 | # | ||||
| 74 | sub AUTOLOAD { | ||||
| 75 | my $method = $AUTOLOAD; | ||||
| 76 | $method =~ s/.*:://; | ||||
| 77 | my $self = shift; tied(*$self)->$method(\@_); | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | #------------------------------ | ||||
| 81 | # PRELOAD | ||||
| 82 | #------------------------------ | ||||
| 83 | # Utility. | ||||
| 84 | # | ||||
| 85 | # Most methods like print(), getline(), etc. which work on the tied object | ||||
| 86 | # via Perl's i/o operators (like 'print') are inherited from IO::Handle. | ||||
| 87 | # | ||||
| 88 | # Other methods, like seek() and sref(), we must delegate ourselves. | ||||
| 89 | # AUTOLOAD takes care of these. | ||||
| 90 | # | ||||
| 91 | # However, it may be necessary to preload delegators into your | ||||
| 92 | # own class. PRELOAD will do this. | ||||
| 93 | # | ||||
| 94 | # spent 1.98ms within IO::WrapTie::Master::PRELOAD which was called:
# once (1.98ms+0s) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@26 at line 105 | ||||
| 95 | 1 | 4µs | my $class = shift; | ||
| 96 | 1 | 43µs | foreach (@_) { | ||
| 97 | 10 | 1.96ms | eval "sub ${class}::$_ { my \$s = shift; tied(*\$s)->$_(\@_) }"; # spent 0s executing statements in string eval | ||
| 98 | } | ||||
| 99 | } | ||||
| 100 | |||||
| 101 | # Preload delegators for some standard methods which we can't simply | ||||
| 102 | # inherit from IO::Handle... for example, some IO::Handle methods | ||||
| 103 | # assume that there is an underlying file descriptor. | ||||
| 104 | # | ||||
| 105 | 1 | 26µs | 1 | 1.98ms | PRELOAD IO::WrapTie::Master # spent 1.98ms making 1 call to IO::WrapTie::Master::PRELOAD |
| 106 | qw(open opened close read clearerr eof seek tell setpos getpos); | ||||
| 107 | |||||
| - - | |||||
| 110 | #------------------------------------------------------------ | ||||
| 111 | package IO::WrapTie::Slave; | ||||
| 112 | #------------------------------------------------------------ | ||||
| 113 | # Teeny private class providing a new_tie constructor... | ||||
| 114 | # | ||||
| 115 | # HOW IT ALL WORKS: | ||||
| 116 | # | ||||
| 117 | # Slaves inherit from this class. | ||||
| 118 | # | ||||
| 119 | # When you send a new_tie() message to a tie-slave class (like IO::Scalar), | ||||
| 120 | # it first determines what class should provide its master, via TIE_MASTER. | ||||
| 121 | # In this case, IO::Scalar->TIE_MASTER would return IO::Scalar::Master. | ||||
| 122 | # Then, we create a new master (an IO::Scalar::Master) with the same args | ||||
| 123 | # sent to new_tie. | ||||
| 124 | # | ||||
| 125 | # In general, the new() method of the master is inherited directly | ||||
| 126 | # from IO::WrapTie::Master. | ||||
| 127 | # | ||||
| 128 | sub new_tie { | ||||
| 129 | my $self = shift; | ||||
| 130 | $self->TIE_MASTER->new($self,@_); ### e.g., IO::Scalar::Master->new(@_) | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | # Default class method for new_tie(). | ||||
| 134 | # All your tie-slave class (like IO::Scalar) has to do is override this | ||||
| 135 | # method with a method that returns the name of an appropriate "master" | ||||
| 136 | # class for tying that slave. | ||||
| 137 | # | ||||
| 138 | sub TIE_MASTER { 'IO::WrapTie::Master' } | ||||
| 139 | |||||
| 140 | #------------------------------ | ||||
| 141 | 1 | 31µs | 1; | ||
| 142 | __END__ |