Question

I have a CGI script that serves up images using the File::Copy CPAN module:

use File::Copy;
.... (set appropriate content header)
binmode STDOUT;
copy $imageFile, \*STDOUT || die "Image delivery failed: $!";

This works fine under CGI but when run under mod_perl I get:

[File::Copy::copy 140]  stat() on unopened filehandle STDOUT at /usr/share/perl/5.14/File/Copy.pm line 140.

I'm not sure if this is expected behaviour or if there's a bug somewhere. I'm new to mod_perl and find I am drowning in a sea of documentation at the moment. Is there any way to change my script so it runs fine under CGI or mod_perl without changes?

Was it helpful?

Solution

Not unless you're willing to change File::Copy or mod_perl (in negative ways). File::Copy expects a file handle associated with a system file handle, but STDOUT is a tied file handle.

OTHER TIPS

From the mod_perl documentation

Under mod_perl, CORE::print( ) (using either STDOUT as a filehandle argument or no filehandle at all) will redirect output to Apache::print( ), since the STDOUT file handle is tied to Apache.

And from the BUGS section if perltie

Tied filehandles are still incomplete. sysopen(), truncate(), flock(), fcntl(), stat() and -X can't currently be trapped.

You can read more about this in the bug report at https://rt.perl.org/rt3//Public/Bug/Display.html?id=112164 if you wish.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top