You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Peter Wood <pw...@christianbook.com> on 2008/02/28 15:33:58 UTC

Modify output of Apache::PerlRun?

Greetings,

I'm running Apache 1.3.28 and mod_perl 1.27. I have quite a few Perl CGI
scripts that run via Apache::PerlRun and product HTML output. I'd like
to be able to modify the HTML output of these scripts after they finish
running, so as to insert some HTML code on a site-wide basis without
having to modify each individual script. My first thought was to
subclass Apache::PerlRun, specifically to provide a custom routine to
modify the output just before it is sent to the client. However, after
taking a long look at Apache::PerlRun, I'm not sure if this is even
possible.

I'd appreciate any suggestions on how to accomplish my task.

Thanks!

Peter

Re: Modify output of Apache::PerlRun?

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, Mar 10, 2008 at 10:28 AM, Peter Wood <pw...@christianbook.com> wrote:
>  Also, just for future reference, the maintainer of Apache::Filter, Ken
>  Williams, has indicated to me that he is no longer able to support any
>  of his Apache::* modules, and recommends going to the mod_perl mailing
>  list for support.

The code for Apache::Filter is relatively simple, so I expect it won't
be a problem to keep it going.  Apache 2 has filtering built in, so it
only needs maintenance for Apache 1 users anyway.

- Perrin

RE: Modify output of Apache::PerlRun?

Posted by Peter Wood <pw...@christianbook.com>.
Howdy,

Thanks for the PerlSendHeader tip! It was set to 'On' for the host I was
working with, and after changing it to 'Off', things started working.
We're using CGI.pm to print out HTTP headers for all of our CGI scripts,
so PerlSendHeader shouldn't be necessary. I'm assuming that there must
have been some conflict between the parsing/reformatting PerlSendHeader
did, and that done by Apache::PerlRunFilter - perhaps PerlSendHeader was
sending one less newline than PerlRunFilter was expecting, and it
therefore chomped an extra line? It would be nice to understand exactly
why this fixed the problem, but for now I'm happy just with the fix.

Also, just for future reference, the maintainer of Apache::Filter, Ken
Williams, has indicated to me that he is no longer able to support any
of his Apache::* modules, and recommends going to the mod_perl mailing
list for support. Glad I did!

Thanks again,

Peter

> -----Original Message-----
> From: pharkins@gmail.com [mailto:pharkins@gmail.com] On 
> Behalf Of Perrin Harkins
> Sent: Friday, March 07, 2008 3:26 PM
> To: Peter Wood
> Cc: modperl@perl.apache.org
> Subject: Re: Modify output of Apache::PerlRun?
> 
> 
> On Fri, Mar 7, 2008 at 1:27 PM, Peter Wood 
> <pw...@christianbook.com> wrote:
> > So, I've given Apache::Filter and Apache::PerlRunFilter 
> (from CPAN) a  
> > shot, and the actual filtering action seems to work as expected, 
> > except  that just before my own filter is applied, the 
> first line of 
> > input goes  missing.
> 
> I don't know what's going on, but I can confirm that this 
> didn't happen to me when I used this module years ago.  Have 
> you tried playing with PerlSendHeader?
> 
> - Perrin
> 

Re: Modify output of Apache::PerlRun?

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, Mar 7, 2008 at 1:27 PM, Peter Wood <pw...@christianbook.com> wrote:
> So, I've given Apache::Filter and Apache::PerlRunFilter (from CPAN) a
>  shot, and the actual filtering action seems to work as expected, except
>  that just before my own filter is applied, the first line of input goes
>  missing.

I don't know what's going on, but I can confirm that this didn't
happen to me when I used this module years ago.  Have you tried
playing with PerlSendHeader?

- Perrin

RE: Modify output of Apache::PerlRun?

Posted by Peter Wood <pw...@christianbook.com>.
So, I've given Apache::Filter and Apache::PerlRunFilter (from CPAN) a
shot, and the actual filtering action seems to work as expected, except
that just before my own filter is applied, the first line of input goes
missing. This usually results in the <html> tag at the top of the page
being removed. This happens even if my filter is totally benign:

sub handler {
    my $r = shift->filter_register;
    my $fh = $r->filter_input();
    while (<$fh>) {
        print $line;
    }
}

I've emailed the maintainer of the module, but I'm not sure of his
availability. So I'm wondering if anyone here has a suggestion.

Thanks,

Peter

> -----Original Message-----
> From: pharkins@gmail.com [mailto:pharkins@gmail.com] On 
> Behalf Of Perrin Harkins
> Sent: Tuesday, March 04, 2008 8:13 PM
> To: Peter Wood
> Cc: modperl@perl.apache.org
> Subject: Re: Modify output of Apache::PerlRun?
> 
> 
> On Thu, Feb 28, 2008 at 9:33 AM, Peter Wood 
> <pw...@christianbook.com> wrote:
> >  I'm running Apache 1.3.28 and mod_perl 1.27. I have quite 
> a few Perl 
> > CGI  scripts that run via Apache::PerlRun and product HTML 
> output. I'd 
> > like  to be able to modify the HTML output of these scripts 
> after they 
> > finish  running, so as to insert some HTML code on a 
> site-wide basis 
> > without  having to modify each individual script.
> 
> I'd suggest you look at Apache::Filter.  It should be able to 
> do this for you.
> 
> - Perrin
> 

Re: Modify output of Apache::PerlRun?

Posted by André Warnier <aw...@ice-sa.com>.
Peter Wood wrote:
[..]

> I've had other experiences where I found a module that already did
> something I was trying to do, but this is the first time I've started
> writing one with the exact same name. :-)
> 
If you write further modules, to avoid name clashes you might also want 
to avoid names such as Cookie, Request, Response, etc..

;-)

André


RE: Modify output of Apache::PerlRun?

Posted by Peter Wood <pw...@christianbook.com>.
Ironically, I had already started writing my own class called
Apache::Filter (which I had intended to implement within each CGI
script), completely unaware that a class with that name already existed,
and did exactly what I was looking for. This will be much better and
save lots of time.

I've had other experiences where I found a module that already did
something I was trying to do, but this is the first time I've started
writing one with the exact same name. :-)

Thanks,

Peter

> -----Original Message-----
> From: pharkins@gmail.com [mailto:pharkins@gmail.com] On 
> Behalf Of Perrin Harkins
> Sent: Tuesday, March 04, 2008 8:13 PM
> To: Peter Wood
> Cc: modperl@perl.apache.org
> Subject: Re: Modify output of Apache::PerlRun?
> 
> 
> On Thu, Feb 28, 2008 at 9:33 AM, Peter Wood 
> <pw...@christianbook.com> wrote:
> >  I'm running Apache 1.3.28 and mod_perl 1.27. I have quite 
> a few Perl 
> > CGI  scripts that run via Apache::PerlRun and product HTML 
> output. I'd 
> > like  to be able to modify the HTML output of these scripts 
> after they 
> > finish  running, so as to insert some HTML code on a 
> site-wide basis 
> > without  having to modify each individual script.
> 
> I'd suggest you look at Apache::Filter.  It should be able to 
> do this for you.
> 
> - Perrin
> 

Re: Modify output of Apache::PerlRun?

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, Feb 28, 2008 at 9:33 AM, Peter Wood <pw...@christianbook.com> wrote:
>  I'm running Apache 1.3.28 and mod_perl 1.27. I have quite a few Perl CGI
>  scripts that run via Apache::PerlRun and product HTML output. I'd like
>  to be able to modify the HTML output of these scripts after they finish
>  running, so as to insert some HTML code on a site-wide basis without
>  having to modify each individual script.

I'd suggest you look at Apache::Filter.  It should be able to do this for you.

- Perrin