Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: source filtering and mod_perl2

by Logicus (Initiate)
on Aug 28, 2011 at 20:33 UTC ( [id://922918]=note: print w/replies, xml ) Need Help??

in reply to Re: source filtering and mod_perl2
in thread source filtering and mod_perl2

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>

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

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

        Looking at (the source of) Apache::PerlRun, it basically is:

        my %orig_inc = %INC; my $eval = join '', 'package ', $package, ';use Apache qw(exit);', $line, $$code, "\n"; $rc = $pr->compile(\$eval);

        ... and as $code gets loaded by a plain file read, source filters never get the chance to actually modify the code.

        You could maybe use a two-level scheme of having the first code be a wrapper that loads your to-be-filtered code. Personally, I would look instead at Plack/PSGI, which eliminates much of the middle man and should work with source filters. When it comes to deploying, source filters also should still work, and if not, you can always use Apache as a transparent proxy in front of your plack application.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-23 01:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found