Mason::Manual::UpgradingFromMason1(3pm)

NAME
Mason::Manual::UpgradingFromMason1 - Summary of differences between Mason 1 and Mason 2

DESCRIPTION
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. :))

ARCHITECTURE

•   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.

•   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.

MAJOR FEATURES

•   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 all web integration has been split out into a companion web framework, Poet, which in turn uses PSGI to integrate with any server backend. You can also use Mason as the templating layer in popular web frameworks such as Catalyst and Dancer. There is no longer anything 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 Plack 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 <http://fuse.sourceforge.net/> 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.

SYNTAX

•   "<%once>" has been replaced with "<%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.

•   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>" and "<%shared>" are gone. Use Moose attributes instead.

•   The "<%ARGS>" hash is gone, you can instead use "$.args" or "$self->args" to get all the parameters passed to a component.

•   "<%method>" and "<%def>" have been replaced with just "<%method>", which creates a true class method rather than a subcomponent.

•   The "<%filter>" tag is now used to define filters, instead of automatically applying a filter to the current component.

•   "Components with content" syntax has been eliminated; use the CompCall filter instead.

•   "Escape flags" in substitution tags now utilize filters.

MISC PARAMETER CHANGES

  Interp parameters

•   "buffer_preallocate_size", "code_cache_max_size" and "use_object_files" have been deemed unnecessary and eliminated.

•   "escape_flags" has been eliminated; define filters instead.

•   "data_dir" now defaults to a directory created with tempdir.

•   "preloads" has been eliminated; this code does roughly the same:

        $interp->load($_) for (grep { /some_condition/ } $interp->all_paths);

  Request parameters

•   "autoflush" and "max_recurse" have been eliminated because they are too difficult to implement efficiently.

  Compiler parameters

•   "preprocess", "postprocess_perl", and "postprocess_text" have been eliminated; similar effects can be achieved with plugins targeting Mason::Compilation.

•   "default_escape_flags" has been eliminated, but see Mason::Plugin::DefaultFilter for a third-party substitute.

MISC METHOD CHANGES

  Interp methods

•   "exec" has been renamed to run.

  Request methods

•   "cache_self" has been eliminated; use the Cache filter instead.

•   "callers", "caller" and "caller_args" have been eliminated; now that component calls are simply method calls underneath, they are too difficult to implement efficiently.

•   "call_next" has been replaced with Moose's "inner".

•   "call_self" has been eliminated; use filters instead.

•   "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.

•   "dhandler_arg" has been renamed to path_info.

•   "exec" has been renamed to run.

•   "fetch_comp" has been renamed to load.

•   "subexec" has been replaced with visit and go.

SEE ALSO
Mason

AUTHOR
Jonathan Swartz <swartz@pobox.com>

COPYRIGHT AND LICENSE
This software is copyright (c) 2012 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.