[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Problem autoloading IO::Handle



At 08:57 1999-09-21 -0400, Paul J. Schinder wrote:
>At 1:24 PM +0100 9/21/99, Peter Westlake wrote:
>
>>I have a script that uses FileHandle and IO, and I get the error message
>>"# Can't locate auto/IO/Handle/open.al in @INC." This is fair enough,
>>since there is no such file, but what is looking for it and why? How
>>do I start debugging this?
>
>
>By showing us the part of the code that's failing.  FileHandle has an 
>open method, which it inherits from IO::File.  IO::Handle does not 
>have an open method.  Something must be wrong with the code.

Ah, so it's looking for an open method on an IO::Handle object?
A suspicion dawns ... regardless of what Certain Other Platforms
may do, perhaps MacPerl's STDOUT is not a FileHandle! Here's the
code, which works on Windows NT:

###################################################################
# Redirect STDOUT and STDERR to a log file, and restore them again.
###################################################################

package Log;

use FileHandle;
use Carp;
use Complain;
use IO;

STDOUT->autoflush();
STDERR->autoflush();

my @stack = ();

sub Push
{
	my $logfile = @_? shift: 'log.txt';
	my $saveout = new IO::File or moan 'could not create $saveout';
	my $saveerr = new IO::File or moan 'could not create $saveerr';
	$saveout->fdopen(STDOUT, '>') or moan "could not fdopen STDOUT: $!";
	$saveerr->fdopen(STDERR, '>') or moan "could not fdopen STDERR: $!";
	push @stack, [$saveout, $saveerr, $logfile];

### The offending line:
	STDOUT->open($logfile, ">>") or moan "could not fdopen STDOUT: $!";
###
	STDERR->fdopen(STDOUT, ">>") or moan "could not fdopen STDERR: $!";
	STDOUT->autoflush();
	STDERR->autoflush();
}

sub Pop {
	my ($saveout, $saveerr, $logfile) = @{pop @stack};
	close(STDOUT);
	close(STDERR);
	STDOUT->fdopen($saveout, '>>') or moan 'could not fdopen $saveout';
	STDERR->fdopen($saveerr, '>>') or moan 'could not fdopen $saveerr';
	$saveout->close;
	$saveerr->close;
	STDOUT->autoflush();
	STDERR->autoflush();
	return $logfile;
}

sub Current
{
	return $stack[$#stack]->[2];
}

1;
__END__

Many thanks,

Peter.


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org