Modify output of Apache::PerlRun?

Modify output of Apache::PerlRun?

am 28.02.2008 15:33:58 von Peter Wood

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?

am 05.03.2008 02:12:48 von Perrin Harkins

On Thu, Feb 28, 2008 at 9:33 AM, Peter Wood 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?

am 05.03.2008 14:32:18 von Peter Wood

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=20
> 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?
>=20
>=20
> On Thu, Feb 28, 2008 at 9:33 AM, Peter Wood=20
> wrote:
> > I'm running Apache 1.3.28 and mod_perl 1.27. I have quite=20
> a few Perl=20
> > CGI scripts that run via Apache::PerlRun and product HTML=20
> output. I'd=20
> > like to be able to modify the HTML output of these scripts=20
> after they=20
> > finish running, so as to insert some HTML code on a=20
> site-wide basis=20
> > without having to modify each individual script.
>=20
> I'd suggest you look at Apache::Filter. It should be able to=20
> do this for you.
>=20
> - Perrin
>=20

Re: Modify output of Apache::PerlRun?

am 05.03.2008 14:44:00 von aw

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?

am 07.03.2008 19:27:23 von Peter Wood

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 tag at the top of the page
being removed. This happens even if my filter is totally benign:

sub handler {
my $r =3D shift->filter_register;
my $fh =3D $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=20
> 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?
>=20
>=20
> On Thu, Feb 28, 2008 at 9:33 AM, Peter Wood=20
> wrote:
> > I'm running Apache 1.3.28 and mod_perl 1.27. I have quite=20
> a few Perl=20
> > CGI scripts that run via Apache::PerlRun and product HTML=20
> output. I'd=20
> > like to be able to modify the HTML output of these scripts=20
> after they=20
> > finish running, so as to insert some HTML code on a=20
> site-wide basis=20
> > without having to modify each individual script.
>=20
> I'd suggest you look at Apache::Filter. It should be able to=20
> do this for you.
>=20
> - Perrin
>=20

Re: Modify output of Apache::PerlRun?

am 07.03.2008 21:25:50 von Perrin Harkins

On Fri, Mar 7, 2008 at 1:27 PM, Peter Wood 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?

am 10.03.2008 15:28:32 von Peter Wood

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=20
> 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?
>=20
>=20
> On Fri, Mar 7, 2008 at 1:27 PM, Peter Wood=20
> wrote:
> > So, I've given Apache::Filter and Apache::PerlRunFilter=20
> (from CPAN) a =20
> > shot, and the actual filtering action seems to work as expected,=20
> > except that just before my own filter is applied, the=20
> first line of=20
> > input goes missing.
>=20
> I don't know what's going on, but I can confirm that this=20
> didn't happen to me when I used this module years ago. Have=20
> you tried playing with PerlSendHeader?
>=20
> - Perrin
>=20

Re: Modify output of Apache::PerlRun?

am 10.03.2008 15:41:42 von Perrin Harkins

On Mon, Mar 10, 2008 at 10:28 AM, Peter Wood 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