Wednesday, January 31, 2007

ModPerl::Util::exit: (120000) exit was called at /var/www/mason_example/test.html line 4

We're thinking of upgrading from Apache 1.3 to Apache 2, so I did an install of Apache 2 on a new box. The box is running the Debian/Sarge flavor of Linux and our site runs on Perl/Mason. I used "aptitude" to install most packages; only in a few cases did I need to get Perl modules from CPAN directly. Here are some of the packages I installed:
  • apache2
  • libapache2-mod-perl2 [ actually version 1.999.21 ]
  • libhtml-mason-perl
Aptitude installs version 1.26 of Mason, even though the most recent version of Mason is 1.35. It installs Apache/2.0.54.

Although most of the migration went fine, I quickly ran into trouble in getting an error from a number of my Perl/Mason files. I created a very simple file, test.html, that demonstrates the problem:

<%/init>
print "This is a script.";
exit();
</%init>


On my Apache 1.3 server, which also uses Mason 1.26, the output looks like this:

This is a script.

On my new Apache 2 server, the output looks like this:

ModPerl::Util::exit: (120000) exit was called at /var/www/mason_example/test.html line 3

I don't see why I'm getting this message; it's ok to call exit in mod_perl:
Normally you will use the plain exit() in your code. You don't need to use ModPerl::Util::exit explicitly...

I have searched high and low for the solution to this, and I'm about ready to give up. There are only a few calls to exit() in our scripts, and I can easily run through and change them to return, which seems to eliminate the error/warning message. But I'm amazed that practically no one else has reported this problem, given the fact that my setup was so plain-vanilla.

Tuesday, January 23, 2007

Perl Mason handles Javascript incorrectly?

I installed Apache2 with Perl/Mason on a machine, and right off the bat it seemed to handle some file types, .java and .js, incorrectly. I didn't realize what was happening at first, so to test the setup, I added a small Mason file, test.html, to the /mason_example directory. The contents of that file were as follows:
<%args>
$hello => ''
</%args>

<script src="test.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
<%perl>
if (!$hello) {
$hello = "hello";
}
</%perl>
alert("from script: <% $hello %>");
hello("<% $hello %>");
</script>

Here is the content of test.js:
var hello  = function(str) {
alert(str);
}
When I hit test.html in a browser (e.g. http://www.example.com/mason_example/test.html), I would see the from script:.. alert, but the Javascript console would display an error indicating that test.js was not being interpreted as Javascript:
Error: syntax error
Source File: http://www.example.com/mason_example/test.js
Line: 1
Source Code:

Error: hello is not defined
Source File: http://www.example.com/mason_example/test.html?hello=hello
Line: 19
After doing a bit of research, I found a solution at MasonHQ:
What's needed is a simple way for mason to be told to try and handle everything that is either html or txt or cgi or in fact anything but some kind of media file or css or js.
I used the workaround suggested there. I changed the FilesMatch stanza in libhtml-mason-perl-examples.conf as follows:
<Directory /var/www/mason_example>
<FilesMatch "(\.html|\.txt|^[^\.]+)$>
# <FilesMatch [^/]>
SetHandler perl-script
PerlResponsehandler HTML::Mason::ApacheHandler
# Only CGI is supported with mod_perl2 currently
PerlSetVar MasonArgsMethod CGI
</FilesMatch>
<FilesMatch "\.(js|css|java)$">
SetHandler default-handler
</FilesMatch>
<Directory>
Now my Javascript files are working, hooray!