I wrote a quick handler that implements a regex as a PerlHandler
maybe this will help to strip out comments:
(oh, and if anyone would like to see this as an official module, I can clean
it up and release it - I didn't really think there would be much interest in
it when I wrote it...)
package Custom::Regex;
#---------------------------------------------------------------------
# usage: PerlHandler Custom::Regex
#
# the following variables will be entered into a regex as:
# s/$RegexChange/$RegexTo/eeg
#
# PerlSetVar RegexChange "change this"
# PerlSetVar RegexTo "to that"
#
# PerlSetVar Filter On # optional - will work within
# # Apache::Filter
#---------------------------------------------------------------------
use Apache::Constants qw( OK DECLINED SERVER_ERROR );
use Apache::File;
use Apache::Log;
use strict;
$Custom::Regex::VERSION = '0.01';
sub handler {
#---------------------------------------------------------------------
# initialize request object and variables
#---------------------------------------------------------------------
my $r = shift;
my $log = $r->server->log;
my $change = $r->dir_config('RegexChange') || undef;
my $to = $r->dir_config('RegexTo') || undef;
# make Apache::Filter aware
my $filter = $r->dir_config('Filter') =~ m/On/i ? 1 : 0;
my ($fh, $status, $output);
#---------------------------------------------------------------------
# do some preliminary stuff...
#---------------------------------------------------------------------
$log->info("Using Custom::Regex");
unless ($r->content_type eq 'text/html') {
$log->info("\trequest is not for an html document - skipping...");
$log->info("Exiting Custom::Regex");
return DECLINED;
}
#---------------------------------------------------------------------
# get the filehandle
#---------------------------------------------------------------------
if ($filter) {
$log->info("\tgetting input from Apache::Filter");
($fh, $status) = $r->filter_input;
} else {
$log->info("\tgetting input from requested Apache::File");
$fh = Apache::File->new($r->filename);
}
if (!$fh || $status ne OK) {
$log->warn("\tcannot open request! $!");
$log->info("Exiting Custom::Regex");
return DECLINED;
}
#---------------------------------------------------------------------
# do the regex on the request
#---------------------------------------------------------------------
if ($change && $to) {
$log->info("\tsubstituting $to for $change");
while (<$fh>) {
my $output;
eval { ($output = $_) =~ s/$change/$to/eeg };
if ($@) {
$log->error("\tsubstitution error: $@");
$log->info("Exiting Custom::Regex");
return SERVER_ERROR;
} else {
print $output;
}
}
}
#---------------------------------------------------------------------
# wrap up...
#---------------------------------------------------------------------
$log->info("Exiting Custom::Regex");
return OK;
}
1;
--Geoff
> -----Original Message-----
> From: Dave DeMaagd [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 22, 2000 11:15 AM
> To: [EMAIL PROTECTED]
> Subject: stripping CRLF on the way out?
>
>
> Have an application that generates nicely formatted HTML (from
> templates, so that they can be easily edited), but since there's a
> awful lot of extra line breaks (and other things, like comments) that
> we'd like to strip out (save bandwidth), is there an easy way to do
> this via mod_perl, something like a PerlOutputHandler???
>
> Something like this would be a far sight easier than having to rewrite
> all of the scripts to do this themselves...
>
> Any advice would help greatly!
>
> --
> Dave DeMaagd - [EMAIL PROTECTED] - http://www.spinynorm.net
> I don't have a solution, but I admire your problem.
> SysAdmin/Programmer - TheImageGroup - ===|:=P~~~~
>