Mason:...Mason1(3pm)
π Mason::Manual::UpgradingFromMason1 β a lil guide bestie π
Perl documentation, user contributed, and it's the Mason::Manual::UpgradingFromMason1 page, which is the whole "so you're moving from Mason 1 to Mason 2" situation. β¨
πΈ NAME πΈ
Mason::Manual::UpgradingFromMason1 β a summary of the differences between Mason 1 and Mason 2. iykyk π«Ά
π¦ DESCRIPTION π¦
okay so Mason 2.x shows up a whole ten years after Mason 1.0 (the one you know as HTML::Mason) and twelve years after the original Mason release dropped. it got rearchitected and reimplemented from the ground up, no cap π
that being said tho β the philosophy and the core syntax are similar enough that it should still be recognizable and still "feel like Mason" to the existing girlies. π
this manual is literally just trying to summarize the differences between Mason 1 and 2, so existing users can decide if they're interested and, if they are, migrate their projects. π
lowkey there is currently no automated way to convert a Mason 1 site to a Mason 2 site, but hopefully someday there will be. (Contributions welcome. :)) π₯Ί
β¨ ARCHITECTURE β¨
- in Mason 1, each component was an instance of a common
Componentclass. in Mason 2, each component is its own Moose class, with a class name generated from the component path. it's giving glow-up π - the main component body β the content and the inline Perl sections β gets 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 get passed to the constructor and placed in attributes. periodt.
π₯ 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_perland was part of the core. in Mason 2, all web integration has been split out into a companion web framework,Poet, which in turn usesPSGIto integrate with any server backend. you can also use Mason as the templating layer in popular web frameworks such asCatalystandDancer. there is no longer anything web-specific in the Mason core. π«Ά - subcomponents have been eliminated, replaced with class methods. bye bestie π
- error processing/formatting has been eliminated. Mason now simply throws fatal errors to the caller. in a Plack environment,
Plack::Middleware::StackTracewill catch the error and format it nicely. slay β¨ - 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->cachesimply returns aCHIobject with an appropriate namespace for the component. iconic.
π 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 useadd_cleanupto 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. we love a clean output πΈ
- 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$.argsor$self->argsto 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 theCompCallfilter 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 withtempdir."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 targetingMason::Compilation."default_escape_flags"has been eliminated, but seeMason::Plugin::DefaultFilterfor a third-party substitute. π
π MISC METHOD CHANGES π
π Interp methods
"exec"has been renamed torun.
π Request methods
"cache_self"has been eliminated; use theCachefilter 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 callcurrent_comp_class, which will at least get you the class. π«Ά"dhandler_arg"has been renamed topath_info."exec"has been renamed torun."fetch_comp"has been renamed toload."subexec"has been replaced withvisitandgo.
π¦ 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. π
k that's the whole thing bestie!! this page came from the User Contributed Perl Documentation for perl v5.34.0, dated 2022-05-27, and it's filed under Mason:...Mason1(3pm). go forth and migrate, you got this π
β¨πΈ
π¦ where this page comes from
- debian bookworm: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmason-perl 2.24-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