Mason::Manual::UpgradingFromMason1 - Summary of differences between Mason 1 and Mason 2
Mason 2.x comes ten years after Mason 1.0 (known as HTML::Mason) and twelve years after the original Mason release. It has been rearchitected and reimplemented from the ground up.
That said, the philosophy and core syntax are similar enough that it should still be recognizable and "feel like Mason" to existing users.
This manual attempts to summarize the differences between Mason 1 and 2, to help existing users decide if they are interested and, if so, migrate their projects.
There is currently no automated way to convert a Mason 1 to a Mason 2 site, but there hopefully will be someday. (Contributions welcome. :))
In Mason 1, each component was an instance of a common Component class. In Mason 2, each component is its own Moose class, with a class name generated from the component path.
The main component body - the content and the inline Perl sections - are placed into a main method.
main
Calling a component (via <& &> or $m->comp ) entails creating a new instance of the component class, and calling its main method. Component call parameters are passed to the constructor and placed in attributes.
<& &>
$m->comp
Plugins now utilize Moose roles and are much more powerful and flexible than in Mason 1. Some features that were (or would have been) in the core of Mason 1 are now in plugins. See Mason::Manual::Plugins.
Web integration in Mason 1 was centered around mod_perl and was part of the core. In Mason 2 it is implemented in a few plugins, most notably PSGIHandler. There is nothing web-specific in the Mason core.
Subcomponents have been eliminated, replaced with class methods.
Error processing/formatting has been eliminated. Mason now simply throws fatal errors to the caller. In a PSGI environment, Plack::Middleware::StackTrace will catch the error and format it nicely.
Resolvers and Anonymous components have been eliminated. Components need to be in files. If your components live in another data source, you could use FUSE or a custom plugin to keep a file hierarchy up to date with the data source.
Caching support has been simplified. $m->cache simply returns a CHI object with an appropriate namespace for the component.
$m->cache
<%once> has been replaced with <%class>.
<%once>
<%class>
<%cleanup> has been eliminated; it was not very useful anyway, since it was not guaranteed to run after an exception. You can use add_cleanup to add cleanup code for the end of the request, which is good enough in most cases, or you can add a DEMOLISH method to the component.
<%cleanup>
DEMOLISH
Single blank lines between blocks are now removed, so you can space blocks out for readability without generating a ton of newlines.
Whitespace is required after a %-line and around the expression in a <% %> tag. This improves readability and leaves open the possibility of additional syntax.
<% %>
<%args> has changed; it now declares a set of input attributes.
<%args>
<%shared> has changed; it now declares a set of shared attributes.
<%shared>
<%method> and <%def> have been replaced with just <%method>, which creates a true class method rather than a subcomponent.
<%method>
<%def>
The <%filter> tag is now used to define filters, instead of automatically applying a filter to the current component.
<%filter>
Components with content syntax has been eliminated; use the CompCall filter instead.
Components with content
Escape flags in substitution tags now utilize filters.
Escape flags
buffer_preallocate_size, code_cache_max_size and use_object_files have been deemed unnecessary and eliminated.
buffer_preallocate_size
code_cache_max_size
use_object_files
escape_flags has been eliminated; define filters instead.
escape_flags
data_dir now defaults to a directory created with tempdir.
data_dir
preloads has been eliminated; this code does roughly the same:
preloads
$interp->load($_) for (grep { /some_condition/ } $interp->all_paths);
autoflush and max_recurse have been eliminated because they are too difficult to implement efficiently.
autoflush
max_recurse
preprocess, postprocess_perl, and postprocess_text have been eliminated; similar effects can be achieved with plugins targeting Mason::Compilation.
preprocess
postprocess_perl
postprocess_text
exec has been renamed to run.
exec
cache_self has been eliminated; use the Cache filter instead.
cache_self
callers, caller and caller_args have been eliminated; now that component calls are simply method calls underneath, they are too difficult to implement efficiently.
callers
caller
caller_args
call_next has been replaced with Moose's inner.
call_next
inner
call_self has been eliminated; use filters instead.
call_self
current_comp has been eliminated. Within a component, use $self; outside a component you can call current_comp_class, which will at least get you the class.
current_comp
$self
dhandler_arg has been renamed to path_info.
dhandler_arg
fetch_comp has been renamed to load.
fetch_comp
subexec has been replaced with visit and go.
subexec
Mason
Jonathan Swartz <swartz@pobox.com>
This software is copyright (c) 2011 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.
To install Mason, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mason
CPAN shell
perl -MCPAN -e shell install Mason
For more information on module installation, please visit the detailed CPAN module installation guide.