Mason::Component(3pm)
π NAME π
Mason::Component β the Mason Component base class, and honestly? the blueprint of the whole vibe π
β¨ DESCRIPTION β¨
Okay bestie, listen. Every single Mason component corresponds to a unique class that inherits, directly or indirectly, from this base class. That's the whole family tree, no cap π³
A brand new instance of the component class gets created every time a component is called β doesn't matter if it's via a top level request, <& &> tags, or an $m->comp call. And here's the important bit: a component instance is only valid for the Mason request it was created in. One request, one life, main character energy but make it temporary π«Ά
We leave this class as devoid of built-in methods as possible, so you can create methods in your own components without ever worrying about name clashes. She stays out of your way, periodt π
π¦ STRUCTURAL METHODS π¦
This is the standard call chain for the page component (the initial component of a request):
handle -> render -> wrap -> main
In many cases only main will actually do anything. She's carrying the whole team, lowkey π
handle
This is the top-most method called on the page component. Her job is to decide how to handle the request, e.g.
- throw an error (e.g. permission denied) π«
- take some action and redirect (e.g. if handling a form in a web environment)
- defer to another component via
$m->go - render the page
She should not output any content herself. Not one crumb. By default, she simply calls render.
render
This method is invoked from handle on the page component. Her job is to output the full content of the page. By default, she simply calls wrap. Giving nothing but delegation, iconic β¨
wrap
This method is invoked from render on the page component. By convention, wrap is an augmented method, with each superclass calling the next subclass. This is useful for cascading templates in which the top-most superclass generates the surrounding content. It's giving layers on layers on layers π
<%augment wrap>
<h3>Subtitle section</h3>
<div class="main">
<% inner() %>
</div>
</%augment>
By default, wrap simply calls inner() to go to the next subclass, and then main at the bottom subclass.
To override a component's parent wrapper, a component can define its own wrap using method instead of augment:
<%method wrap>
<h3>Parent wrapper will be ignored</h3>
<% inner() %>
</%method>
To do no wrapping at all, call the component class method no_wrap:
<%class>
CLASS->no_wrap;
</%class>
main
This method is invoked when a non-page component is called, and from the default wrap method as well. She consists of the code and output in the main part of the component that is not inside a <%method> or <%class> tag. Just the raw, unfiltered main-part content π
πΈ CLASS METHODS πΈ
no_wrapβ a convenience method that redefines render to callmaininstead ofwrap, thus skipping any content wrapper inherited from parent. She said "no thank you to the family template" π
<%class>
CLASS->no_wrap;
</%class>
allow_path_infoβ this method is called when the request path has apath_infoportion, to determine whether thepath_infois allowed. Default is false. SeeMason::Manual::RequestDispatch.
<%class>
method allow_path_info { 1 }
</%class>
π OTHER METHODS π
argsβ Returns the hashref of arguments passed to this component's constructor, e.g. the arguments passed in a component call. The receipts πcmetaβ Returns theMason::Component::ClassMetaobject associated with this component class, containing information such as the component's path and source file.
my $path = $self->cmeta->path;
mβ Returns the current request. This is also available via$minside Mason components. Your one-stop shop for the whole request, fr fr ποΈ
π 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. Free as in freedom, bestie π¦
Ok that's the whole page, mwah π This was Mason::Component, from the User Contributed Perl Documentation, perl v5.34.0, dated 2022-05-27. Go forth and build components, you absolute legend π
π¦ 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