absolut.todd has asked for the wisdom of the Perl Monks concerning the following question:
I am using this module that I have written:
And early in the program I declare:package Tie::Annotate; use base qw(Tie::FileHandle::Base); use IO::File; use strict; use warnings; sub TIEHANDLE { my $class = shift; my $annotation = shift; my $handle = new IO::File ">> test.err" or die "Cannot open file: +$!\n"; #$self->{FH} = *$FH; return bless {FH => $handle, ann => $annotation}, $class; } sub PRINT { my $self = shift; my $string = shift; my $handle = $self->{FH}; print $handle "$self->{ann} " . $string; } 1;
tie *STDOUT, "Tie::Annotate", 'OUT'; tie *STDERR, "Tie::Annotate", 'ERR';
And this generally works correctly, outputting to STDOUT gets appended to the error log with OUT at the start of the line and STDERR gets appended to the error log with ERR and the start of the line.
But there is a problem; one of the CPAN modules (Cvs) relies on IPC::Run which dies when STDERR and STDOUT are captured like this.
FWIW the actual error message is
Can't call method "slave" on an undefined value at /home/FCS/teh/perl/lib/perl5/site_perl/5.8.5/IPC/Run.pm line 2816
IPC::Run's verion is $VERSION = " 0.80";
Is there something crazy with what im trying to do?
A suggestion of a better way to catch STDOUT and STDERR would be appreciated if there is any... Unfortunatly, Log4Perl is not an option.