HTML::Mason(3pm)
π HTML::Mason π
okay bestie, you're reading the manual page for HTML::Mason, a User Contributed Perl Documentation situation, and honestly? it's giving legendary. it's a High-performance, dynamic web site authoring system, no cap. β¨
β¨ VERSION β¨
you're on version 1.60 β iconic, we stan. π
πΈ SYNOPSIS πΈ
here's the vibe, drop this in your Apache config:
PerlModule HTML::Mason::ApacheHandler
<Location />
SetHandler perl-script
PerlHandler HTML::Mason::ApacheHandler
</Location>
boom. that's it. you're so back. π
π¦ DESCRIPTION π¦
so like, Mason is a whole tool for building, serving and managing large web sites. its features make it the ideal backend for high load sites serving dynamic content β think online newspapers, database driven e-commerce sites, that whole genre. it's highkey built for it.
okay but here's the thing: Mason can actually be used to generate any sort of text, web site or not. but it was originally built for web sites, and since that's why basically everyone cares about it, that's what this doc focuses on. periodt.
Mason's various pieces all revolve around the notion of "components". a component is a mix of HTML, Perl, and special Mason commands β one component per file. so-called "top-level" components represent entire web-pages, while smaller components typically return HTML snippets for embedding in top-level components. this object-like architecture greatly simplifies site maintenance: change a shared component, and you instantly changed all dependent pages that refer to it across a site (or across many virtual sites). it's giving main character energy fr fr. π
Mason's component syntax lets designers separate a web page into programmatic and design elements. meaning the esoteric Perl bits can be hidden near the bottom of a component, preloading simple variables for use above in the HTML. in our own experience, this frees content managers (i.e., non-programmers) to work on the layout without getting mired in programming details. techies, however, still enjoy the full power of Perl. both. both is good. π«Ά
Mason works by intercepting innocent-looking requests (say, http://www.yoursite.com/index.html) and mapping them to requests for Mason components. then Mason compiles the component, runs it, and feeds the output back to the client. slay.
consider this simple Mason component:
% my $noun = 'World';
Hello <% $noun %>!
How are ya?
the output of this component is:
Hello World!
How are ya?
in this component you see a mix of standard HTML and Mason elements. the bare % prefixing the first line tells Mason that this is a line of Perl code. one line below, the embedded <% ... %> tag gets replaced with the return value of its contents, evaluated as a Perl expression. β¨
beyond this trivial example, components can also embed serious chunks of Perl code (say, to pull records from a database). they can also call other components, cache results for later reuse, and perform all the tricks you expect from a regular Perl program. it's literally so much. π
π MAINTENANCE HELP NEEDED π
okay so real talk β I (Dave Rolsky) am no longer using HTML::Mason and I would love to find some co-maintainers to help. specifically, I'd like people to review issues and PRs, create new PRs, and ultimately take on the task of uploading new releases to CPAN. if you're interested the best way to start is to fix one or more of the issues in the issue tracker <https://github.com/houseabsolute/HTML-Mason/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc>. π₯Ί please. we're begging. π
π WAIT - HAVE YOU SEEN MASON 2? π
Version 1 of Mason (this distribution) β has been around since 1998, is in wide use, and is very stable. however it has not changed much in years and is no longer actively developed. she's resting. π
Version 2 of Mason β Mason β was released in February of 2011. it offers a new syntax as well as a number of other features. see <https://metacpan.org/pod/distribution/Mason/lib/Mason/Manual/UpgradingFromMason1.pod> for details of the differences between the two. iykyk. π
π§ INSTALLATION π§
Mason has been tested under Linux, FreeBSD, Solaris, HPUX, and Win32. as an all-Perl solution, it should work on any machine that has working versions of Perl 5.00503+, mod_perl, and the required CPAN modules. lowkey universal.
Mason has a standard MakeMaker-driven installation. see the README file for details. π
π CONFIGURING MASON π
this section assumes that you are able to install and configure a mod_perl server. relevant documentation is available at http://www.apache.org (Apache) and http://perl.apache.org (mod_perl). the mod_perl mailing list, archive, and guide are also great resources. so many resources bestie, eat up. π
the simplest configuration of Mason requires a few lines in your httpd.conf:
PerlModule HTML::Mason::ApacheHandler
<Location />
SetHandler perl-script
PerlHandler HTML::Mason::ApacheHandler
</Location>
the PerlModule directive simply ensures that the Mason code is loaded in the parent process before forking, which can save some memory when running mod_perl. efficiency queen. β¨
the <Location> section routes all requests to the Mason handler, which is a simple way to try out Mason. a more refined setup is discussed in the Controlling Access via Filename Extension section of the administrator's manual.
once you have added the configuration directives, restart the server. first, go to a standard URL on your site to make sure you haven't broken anything. if all goes well you should see the same page as before. if not, recheck your Apache config files and also tail your server's error log. π
if you are getting "404 Not Found" errors even when the files clearly exist, Mason may be having trouble with your document root. one situation that will unfortunately confuse Mason is if your document root goes through a symbolic link. try expressing your document root in terms of the true filesystem path. π
next, try adding the tag <% 2+2 %> at the top of some HTML file. if you reload this page and see a "4", Mason is working! π
π DOCUMENTATION ROADMAP π
once Mason is on its feet, the next step is to write a component or two. the Mason Developer's Manual is a complete tutorial for writing, using, and debugging components. a reference companion to the Developer's Manual is the Request API documentation, HTML::Mason::Request. π
whoever is responsible for setting up and tuning Mason should read the Administrator's Manual, though developers will also benefit from reading it as well. this document covers more advanced configuration scenarios and performance optimization. the reference companion to the Administrator's manual is the Parameters Reference, which describes all the parameters you can use to configure Mason. yes bestie, ALL of them. π
most of this documentation assumes that you're running Mason on top of mod_perl, since that is the most common configuration. if you would like to run Mason via a CGI script, refer to the HTML::Mason::CGIHandler documentation. if you are using Mason from a standalone program, refer to the Using Mason from a Standalone Script section of the administrator's manual. π¦
there is also a book about Mason, Embedding Perl in HTML with Mason, by Dave Rolsky and Ken Williams, published by O'Reilly and Associates. the book's website is at http://www.masonbook.com/. this book goes into detail on a number of topics, and includes a chapter of recipes as well as a sample Mason-based website. a whole BOOK. obsessed. ππ
β GETTING HELP AND SOURCES β
questions and feedback are welcome, and should be directed to the Mason mailing list. you must be subscribed to post. (yes, subscribed. it's the rule.)
https://lists.sourceforge.net/lists/listinfo/mason-users
you can also visit us at "#mason" on <irc://irc.perl.org/#mason>. come hang out, we don't bite. π«Ά
bugs and feature requests will be tracked at RT:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Mason
bug-html-mason@rt.cpan.org
πΈ SUPPORT πΈ
bugs may be submitted at <https://github.com/houseabsolute/HTML-Mason/issues>.
π SOURCE π
the source code repository for HTML-Mason can be found at <https://github.com/houseabsolute/HTML-Mason>.
π AUTHORS π
- Jonathan Swartz
<swartz@pobox.com> - Dave Rolsky
<autarch@urth.org> - Ken Williams
<ken@mathforum.org>
the founding mothers and fathers fr fr. π
π¦ CONTRIBUTORS π¦
- Γvar ArnfjΓΆrΓ° Bjarmason
<avarab@gmail.com> - Alex Balhatchet
<kaoru@slackwise.net> - Alex Vandiver
<alex@chmrr.net> - Florian Schlichting
<fsfs@debian.org> - John Williams
<jwilliams@cpan.org> - Kent Fredric
<kentnl@gentoo.org> - Kevin Falcone
<falcone@bestpractical.com> - Patrick Kane
<modus-cpan@pr.es.to> - Ricardo Signes
<rjbs@cpan.org> - Shlomi Fish
<shlomif@shlomifish.org>
the whole squad. iconic. π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 1998 - 2023 by Jonathan Swartz.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
the full text of the license can be found in the LICENSE file included with this distribution.
bestie, don't sleep on the LICENSE file. it's short, it's sweet, it's legally binding. π
okay and finally, the lil sign-off: this page is from perl v5.38.2, dated 2024-03-05, and it's the HTML::Mason(3pm) manual. now go write some components, you absolute legend. π«Άβ¨π
π¦ where this page comes from
- debian trixie: libhtml-mason-perl 1:1.60-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-mason-perl 1:1.60-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-mason-perl 1:1.60-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms