HTML::Mason is a Perl-based web site development and delivery system. Its main features include:

Components written in the Mason syntax are translated to pure Perl code and cached. The optimal usage scenario of HTML::Mason is to load it in a mod_perl environment within an Apache web server. This way, compiled Perl code stays in memory and is reloaded only when the source is changed. HTML::Mason is highly customizable and is distributed freely as open source. You can get it at CPAN.

The Mason's website is at http://www.masonhq.com.

The alternative systems, with slightly different functionality and philosophy, are HTML::EP, HTML::Embperl, eperl.

I love Perl. It is definitely a language for getting things done, in web world and elsewhere.

But Perl has one problem: It isn't embedded by nature. A CGI program or Apache mod_perl code is a single program - and it has to spew out HTML from the middle of the program.

Thus, I thought PHP was pretty neat - everything can be embedded in middle of pages! But, of course, PHP was not Perl, and at times, I greatly missed the Great Language...

Then I learned of JSP. Holy heck! It had some really good ideas. In PHP, there was just one sort of processing tag to do everything: <?php code... ?>. Now, if I just want to print out contents of the variable, I say <?php echo $variable; ?>. Long? Yes. (Okay, I have been told by many nice people this can be done with <?= $var ?>... this probably wasn't there in PHP3 days =) In JSP, I can say <%= variable %>. But, of course, JSP is primarily a Java solution, and has serious problems with "freedom" of components - I can't just copy a component from one webapp to another without messing with stuff.

And then I learned of HTML::Mason. My dream was complete.

HTML::Mason lets me to put real, live Perl code right into a web page. And I can get a variable out just as easily as in Java: <% $variable %>.

And the components! I can just write a script that does something, takes parameters, too, and embed it right into the page - and this component can be anywhere, and the thing supports search paths of sorts and automagical finding of appropriate component. For example, I could write a component like this:

%#
%# greeter.comp - Example component
%#
<%args>
$username => ""  # User's name
</%args>
<%perl>

# Perl code here!
$m->out("We bring greetings to $username!");

</%perl>

And then call it from middle of the HTML page with arguments:

    <& greeter.comp, username=>'the most magnificent user' &>

And this is not all! All lines that are prefixed with % are interpreted as Perl code. This means that instead of messy PHP like this...

<?php if($user->islate()) { ?>
 Sorry, you're late!
<?php } else { ?>
 You're right on time!
<?php } ?>

I can do this:

% if ($user->islate()) {
 Sorry, you're late!
% } else {
 You're right on time!
% }

(Who's still saying Perl is hard to read, huh? Of course, you could accuse me of picking an unfavoring piece of PHP, but in some situations, it really looks that bad. There are more than one to way to do it in both languages, though, but in this case Perl won...)

And this all coupled to wonderful error reporting, with code displayed or not!

HTML::Mason is definitely one of my new favorite Perl modules. Now, I just wish mod_perl will soon arrive to Apache 2 - even if HTML::Mason doesn't necessarily even need mod_perl to survive, it also works as CGI.

Log in or register to write something here or to contact authors.