You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Arne Skjaerholt <ar...@online.no> on 2004/11/08 18:15:35 UTC

Moving STDOUT to a new handle?

Hello everyone,
I am currently workning on writing a CMS system, and as such I'd like to prevent user modules from outputting data directly instead of using the method supplied by the system. The way I would like to this is opening a new filehandle in the mian module (lexically scoped so noone else can get at it) and then retying STDOUT to a module that logs all attempts to use the filehandle.
Now, having done my research I found that STDOUT is tied to the Apache class, and that simply duping STDOUT isn't sufficient (it doesn't conserve the tie). I also found that saying tie *NEWOUT, "Apache"; doesn't do the necessary magic to make the new handle work.
So, is there a way I can move STDOUT to a new handle, or do I have no other choice than to say "please don't use direct output"?

Thanks in advance,
Arne
:wq


Re: Moving STDOUT to a new handle?

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2004-11-08 at 12:15, Arne Skjaerholt wrote:
> So, is there a way I can move STDOUT to a new handle

Sounds like you're looking for Apache::Filter or Apache::OutputChain. 
There is also a discussion of this in the eagle book:
http://perl.apache.org/docs/offsite/books.html#Writing_Apache_Modules_with_Perl_and_C

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: SV: Moving STDOUT to a new handle?

Posted by William McKee <wi...@knowmad.com>.
On Mon, Nov 08, 2004 at 07:17:21PM +0100, Arne Skjaerholt wrote:
> And, as I think of it, I don't think it'd be terribly useful as
> CGI::Application is intended for use with CGI scripts, not mod_perl
> handlers.

This is not true. Several folks on the C::A list, including myself, are
using it in conjunction with mod_perl. In fact, Michael Peters has just
released a plugin to make it even more mod_perl friendly (including the
use of Apache::* modules rather than CGI.pm).

However, I agree that it does not provide a technical solution to your
problem.


William

-- 
Knowmad Services Inc.
http://www.knowmad.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


SV: SV: Moving STDOUT to a new handle?

Posted by Arne Skjaerholt <ar...@online.no>.
> From: Rob Kinyon [rob.kinyon@gmail.com]
> FYI: C::A has a plugin that will make it work (mostly) seamlessly with
> mod_perl called CGI::Application::Apache.

Hmm. I can't find CGI::Application::Apache on CPAN, only CGI::Application::Plugin::Apache, which, unfortunately for me, doesn't do any STDOUT magic either.

Arne
:wq


SV: Moving STDOUT to a new handle?

Posted by Arne Skjaerholt <ar...@online.no>.
> This might be a lame response, but I would first look at CGI::Application 
> and see how they go about doing this.

It's a good idea, but having looked at the code on CPAN it seems that CGI::Application doesn't do anything with STDOUT, it only states (repeatedly) that at no point should anyone call print() on STDOUT. And, as I think of it, I don't think it'd be terribly useful as CGI::Application is intended for use with CGI scripts, not mod_perl handlers.

Arne
:wq