in reply to Re: Trapping re 'debug'
in thread Trapping re 'debug'

Ok, so I tried that and got marginally closer. At least the "Freeing" line isn't visible anymore. So why isn't PRINT, PRINTF, or WRITE being called with the data? That's really the final bit that would have to work for it to even have a point. The following code outputs nothing except "DESTROY\n".

package TrapRe; sub TIEHANDLE { my $class = shift; my $fh = \do { local *HANDLE }; bless $fh, $class; } sub CLOSE { close $_[0] } eval qq[sub $_ { print "$_\n" };] for qw/READ READLINE GETC WRITE PRINT PRINTF BINMODE EOF FILENO SEEK TELL OPEN DESTROY UNTIE/; package main; BEGIN { close STDERR; tie *STDERR, TrapRe; } use re 'debug'; 1 =~ 1;

Seeking Green geeks in Minnesota

Replies are listed 'Best First'.
Re: Re^2: Trapping re 'debug'
by Anonymous Monk on Jan 27, 2003 at 17:04 UTC

    The reason you only see the DESTROY in your class is because you closed STDERR, then tied it to your class, but in your class you do nothing with it. So then when re 'debug' attempts to print STDERR, perl find that the handle is closed and reopens it before it can output to it. This process of reopening destroys your handle. You get the DESTROY call.

      Fair enough. I removed the call to close STDERR, left the tie *STDERR, TrapRe line in and I still only get the 'DESTROY' note. So at that point I'm just tying the existing STDERR handle but the tied object methods aren't being triggered at all.


      Seeking Green geeks in Minnesota