Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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)


In reply to Apache::Filter and Apache::RegistryFilter by thraxil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2021-04-15 13:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?