Boost Fertility New Invention Ups Success Rates.pdf
Mason 2 - July 2011 - Seattle Perl Users Group
1. Mason 2
True OO templating for Perl
Jonathan Swartz
July 26, 2011
Seattle Perl Users Group
2. What is Mason?
Templating system for generating dynamic content
(e.g. web pages)
<& header.mi &>
<ul>
% foreach my $article (@articles) {
<li>
<a href="<% $article->url %>">
<% $article->title %>
</a>
</li>
%}
</ul>
<& footer.mi &>
3. Mason Timeline
• 1998 - HTML::Mason 0.01
• 2001 - HTML::Mason 1.0
• 2002 - HTML::Mason 1.1, O’Reilly book
• - Used by many mod_perl sites
• 2006 - Amazon switches to Mason
• - The lost years
• 2011 - Mason 2.0
4. History: Past 5 years
• Mason enters stasis mode
• MVC supplants embedded-code
• Web frameworks emerge
• Catalyst+TT becomes Perl web “standard”
• Mason wiki and mail list fills with weeds
• Figured I was done... then they drag me back
5. Why Mason 2?
• New technologies
• Moose
• Plack/PSGI
• Long-desired syntax and features
• Long-standing annoyances
• Changes in how people use Mason today
6. Mason 1 vs 2
It’s called... HTML::Mason Mason
Components are... Instances of a class Classes (Moose)
Web integration
via... mod_perl + glue PSGI
Standardized,
Filenames are... Arbitrary, unenforced
semi-enforced
Plugins are... Limited set of hooks Moose roles
7. Components as Moose Classes
arguments --> attributes
autohandlers --> parent classes
“inheritance” --> inheritance
subcomponents --> methods
common package --> distinct package
anon subroutines --> named subroutines
Plus the power of Moose
(roles, method modifiers, ...)
8. PSGI/Plack
• PSGI - Interface spec between Perl web
apps and servers (like CGI)
• Allows Mason to work from mod_perl,
Perl-only server, standalone script...
• Plack - Common tools, middleware, servers
(debug console, error trace, sessions...)
9. Catalyst/TT vs Mason
Separate M
Separate M, V, and C
Unified V and C
Simplified template
Perl in templates
language
Designer friendly Programmer friendly