After some experimenting -- no, this doesn't work. "Freezing" the write function before the tie() won't help, since the dispatch is happening later, at call time, depending of the then current ties, as can be seen in
#!/usr/bin/perl # # tying knots: how to override a tied filehandle and still access its +guts? use IO::Handle; use Data::Dumper; package Hahandle; use base qw(Tie::Handle); sub TIEHANDLE { my ($class, $ll) = @_; # ll: the "lower level ref" return bless { _ll => $ll, _llwrite => $ll->can('syswrite') }, $class; } sub WRITE { my($self, $buf, $len, $offs) = @_; $buf =~ s/(\w+)/$1 $1/g; # quite dirty syswrite(STDOUT, $buf, length($buf), $offs); } sub llwrite { my $self = shift; $self->{_llwrite}($self->{_ll}, @_); } ################ package main; my $out = IO::Handle->new_from_fd(STDOUT, "w"); $out->write("(0) bong!\n"); my $wr = $out->can('syswrite'); tie(*$out, 'Hahandle', $out); $out->write("(1) bong!\n"); &$wr($out, "(2) bong!\n");
which yields
(0) bong! (1 1) bong bong! (2 2) bong bong!
Gaah. Of course, I might do fdopen before tie()ing, but I guess I'd lose the original tie. Help. Is there a way to "stack ties"?
In reply to Re: IO::Multiplex and tied handles?
by oldtomas
in thread IO::Multiplex and tied handles?
by oldtomas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |