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)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.