[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using perl source code filter in mod_perl2


Is it possible to use perl source code filters (like Filter::Util::Call)
in scripts that are run via ModPerl::Registry?

If I place the following module somewhere in my @INC path:

Hello2Goodbye.pm
----------------
package Hello2Goodbye;
use Filter::Util::Call;
sub import {
	my $type = shift;
	filter_add(bless []);
}
sub filter {
	my $self = shift;
	my $status;
	s/Hello/Goodbye/g if ($status = filter_read()) > 0;
	return $status;
}
1;

and then run the following script via ModPerl::Registry:

filtertest1.pl
--------------
use Hello2Goodbye;
print "Content-Type: text/html\n\n";
print "<HTML><HEAD><TITLE>Filter Test</TITLE></HEAD><BODY>\n";
print "<H1>Hello, world.</H1>\n";
print "</BODY></HTML>\n";

then I get the output "Hello, world." rather than "Goodbye, world.",
i.e. the source code didn't get filtered.

I can make it work by rewriting the script as:

filtertest2.pl
--------------
use FilterTest;
FilterTest::greeting();

where the FilterTest module contains:

FilterTest.pm
-------------
use Hello2Goodbye;
package FilterTest;
sub greeting() {
	print "Content-Type: text/html\n\n";
	print "<HTML><HEAD><TITLE>Filter Test</TITLE></HEAD><BODY>\n";
	print "<H1>Hello, world.</H1>\n";
	print "</BODY></HTML>\n";
}
1;

but I'd really like the scripts themselves to be source-filtered too,
not just the modules that they use.

Any ideas?


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.