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...@broadpark.no> on 2005/05/15 01:37:07 UTC

[QUESTION] Overloading/overriding print() when subclassing Apache

Hello all,
I'm currently working on a project where I've decided to subclass
Apache, and one of the methods I've decided to overload is the print
method (so that my main module decides when data actually gets printed,
not user modules). Now, I'd like to also override the built-in perl
print (like Apache has done) so that module authors can say print
( @my_data ) instead of MyModule::Request->print ( @my_data ).
Currently I've tried  the following:
sub PRINT
{
	MyModule::Request->print ( @_ );
}
*print = \&PRINT;

and:

# Same PRINT() as above.
*CORE::GLOBAL::print = \&PRINT;

and:

*CORE::print = \&PRINT;

None of them have garnered any success worth mentioning. Explicitly
saying MyModule::Request->print ( @my_data ); works as I intended. Does
anyone have any ideas as to what I'm doing wrong here?

Thanks in advance,
Arne
:wq


Re: [QUESTION] Overloading/overriding print() when subclassing Apache

Posted by Arne Skjaerholt <ar...@broadpark.no>.
Ok, sorry for the previous two (rather horrible) mails it's getting to
be the time of night where (really bad) good ideas abound, so I'll just
leave this information before going to bed:
mod_perl-1.27 according to gentoo portage, mod_perl 1.29 according to my
Apache server string.
perl-5.8.5

Arne
:wq


Re: [QUESTION] Overloading/overriding print() when subclassing Apache

Posted by Arne Skjaerholt <ar...@broadpark.no>.
> You don't say which mod_perl version you are using, Arne.
D'oh! I really should've remembered to add that info.
So basically Apache does everything I want on it's own. How clever and,
well, obvious. Thanks for bothering with what I honestly should've
figured out on my own.

Arne
:wq


Re: [QUESTION] Overloading/overriding print() when subclassing Apache

Posted by Stas Bekman <st...@stason.org>.
Arne Skjaerholt wrote:
> Hello all,
> I'm currently working on a project where I've decided to subclass
> Apache, and one of the methods I've decided to overload is the print
> method (so that my main module decides when data actually gets printed,
> not user modules). Now, I'd like to also override the built-in perl
> print (like Apache has done) so that module authors can say print
> ( @my_data ) instead of MyModule::Request->print ( @my_data ).
> Currently I've tried  the following:
> sub PRINT
> {
> 	MyModule::Request->print ( @_ );
> }
> *print = \&PRINT;
> 
> and:
> 
> # Same PRINT() as above.
> *CORE::GLOBAL::print = \&PRINT;
> 
> and:
> 
> *CORE::print = \&PRINT;

> None of them have garnered any success worth mentioning. Explicitly
> saying MyModule::Request->print ( @my_data ); works as I intended. Does
> anyone have any ideas as to what I'm doing wrong here?

You don't say which mod_perl version you are using, Arne.

mp1 uses a tied STDOUT handle, so the correct way to do that is to 
subclass the Apache package with overriden PRINT method.

mp2 uses PerlIO or the tie interfaces depending on the used perl.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com