http://qs1969.pair.com?node_id=922917


in reply to source filtering and mod_perl2

Personally, I would recommend looking at Filter::Simple instead of Filter::Util::Call, as Filter::Simple at least provides a simpler (indeed!) interface to source filters.

But, as you don't show any code we could look at, it is quite hard to tell you what is wrong with your code, or mod_perl2, or how the two interact. My guess is that you have problems with the different Apache backends. For example, I can easily imagine Apache threads not playing well with a source-filtered Perl script, especially when trying to reload.

Replies are listed 'Best First'.
Re^2: source filtering and mod_perl2
by Logicus (Initiate) on Aug 28, 2011 at 20:33 UTC
    Listing test2.cgi ----------------- #!/usr/bin/perl use Modern::Perl; use aXML2; my $stash = { title => "bob's bit's emporium" }; sub a { " foo " } <aXML> <html> <head> <title>[my]stash->{'title'}[/]</title> </head> <body> <perl>print "hi";</perl> (a)b(/) </body> </html> </aXML> listing aXML2.pm ---------------- package aXML2; use Filter::Util::Call; my $header = 'print "Content-type: text/html\n\n";'; sub import { my ($type) = @_; my ($ref) = []; filter_add(bless $ref); } sub filter { my ($self) = @_; my ($status); do { if (s@<aXML>@$header print qq\@@s) { $header = " "; } s@</aXML>@\@;@s; s@<perl>@\@;@s; s@</perl>@print qq\@@s; s@\(([^\(]*?)\)([^\(]*?)\(/\)@\@; print &$1('$2'); print qq +\@@s; s@\[my\](.*?)\[/\]@\$$1@gs; } if $status = filter_read() > 0; $status; } 1;

    test2.cgi works under plain CGI but not under mod_perl using :

    Listing httpd.conf ------------------ AddHandler cgi-script .cgi PerlModule Apache::DBI <Files *.pl> SetHandler perl-script PerlHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI Order allow,deny Allow from all </Files>

      So, how does your script fail? We are not mind readers, and if you don't tell us, it makes it much harder for us to find out whether we are seeing the same issues that you see.

      As a side-note, I think it's unwise to use @ as a delimiter for your filter when @ is quite prone to also occur within the output you are constructing. I would rather use here-documents or some escapement scheme.

        Bareword found where operator expected at /var/www/test2.pl line 20, n +ear "]stash" (Missing operator before stash?) [Sun Aug 28 23:07:59 2011] [error] syntax error at /var/www/test2.pl l +ine 18, near "html>"\n syntax error at /var/www/test2.pl line 20, near "/]</title"\n BEGIN not safe after errors--compilation aborted at /var/www/test2.pl +line 24.\n

        It seems that when I run it under mod_perl the filtering doesn't happen and it tries to run it without it and thus fails. The exact same file is fine as vanilla CGI but when you add the overhead of connecting the database everytime the performance is still pretty poor... 0.04 ~ average per request.