http://www.perlmonks.org?node_id=308230

thraxil has asked for the wisdom of the Perl Monks concerning the following question:

i'm trying to figure out how to write filters using Apache::Filter.

by modifying recipe 15.4 in the Mod_Perl Developer's Cookbook, i've got the following toy filter which just lowercases pages:

package Apache::LC; use Apache::Constants qw(OK DECLINED NOT_FOUND); use Apache::File; use Apache::Log; use strict; sub handler { my $r = shift; return DECLINED unless $r->content_type eq 'text/html'; my $fh = undef; if (lc $r->dir_config('Filter') eq 'on') { $r = $r->filter_register; ($fh,my $status) = $r->filter_input; return $status unless $status == OK; } else { $fh = Apache::File->new($r->filename); return DECLINED unless $fh; } my $dirty = do {local $/; <$fh>}; $r->send_http_header('text/html'); print lc $dirty; return OK; } 1;

with the following in my apache conf, it works just like you'd expect on static html files:

PerlModule Apache::LC PerlModule Apache::Filter <Location /test/filter/> PerlSetVar Filter On SetHandler perl-script PerlHandler Apache::LC </Location>

i'm having trouble getting it to filter the output of Registry scripts though. my understanding is that Apache::RegistryFilter should take care of it. i tried:

PerlModule Apache::LC PerlModule Apache::Filter PerlModule Apache::RegistryFilter <Location /perl/*.pl> PerlSetVar Filter On SetHandler perl-script PerlHandler Apache::RegistryFilter Apache::LC Options -Indexes ExecCGI PerlSendHeader On </Location>

this just spits out the source code for the script. if i remove the 'Apache::LC' from the end of the PerlHandler line, it works like a regular Registry script.

i tried making some other filters from the same template and i could chain them all together without any problems. i just can't seem to get any registry type action in. i also tried some other filter aware modules from CPAN like Apache::Dynagzip, and those seemed to work ok, even with RegistryFilter scripts.

at this point, i'm really not sure if it's a problem with my module, or with the apache config. can anyone spot any obvious problems with either or has anyone else done something similar and have any tips on getting it working?

(this is all with Apache 1.3.28, mod_perl 1.27, and perl 5.8.0)