Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

source filtering and mod_perl2

by Logicus (Initiate)
on Aug 28, 2011 at 19:48 UTC ( #922916=perlquestion: print w/replies, xml ) Need Help??

Logicus has asked for the wisdom of the Perl Monks concerning the following question:

So I was just having alsorts of deviant nooby fun with Filter::Util::Call, when I tried it out with mod_perl2 and it breaks. The same script run as vanilla CGI works just fine. Is there a way around it so I can use source filtering on mod_perl2 apps? or is there prehaps a mod_perl2 version of the same thing?

Replies are listed 'Best First'.
Re: source filtering and mod_perl2
by Corion (Patriarch) on Aug 28, 2011 at 20:14 UTC

    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.

      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 ---------------- 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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://922916]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-08-10 07:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found