Mason::Component - Mason Component base class
version 2.01
Every Mason component corresponds to a unique class that inherits, directly or indirectly, from this base class.
A new instance of the component class is created whenever a component is called - whether via a top level request, <& &> tags, or an << $m->comp >> call.
<& &>
We leave this class as devoid of built-in methods as possible, allowing you to create methods in your own components without worrying about name clashes.
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.
main
This is the top-most method called on the page component. Its job is to decide how to handle the request, e.g.
throw an error (e.g. permission denied)
defer to another component via $m->go
$m->go
redirect to another URL (if in a web environment)
render the page
It should not output any content itself. By default, it simply calls "render".
This method is invoked from "handle" on the page component. Its job is to output the full content of the page. By default, it simply calls "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.
wrap
By default, wrap simply calls inner() to go to the next subclass, and then "main" at the bottom subclass.
inner()
This method is invoked when a non-page component is called, and from the default "wrap" method as well. It consists of the code and output in the main part of the component that is not inside a <%method> or <%class> tag.
<%method>
<%class>
Returns the current request. This is also available via $m inside Mason components.
$m
Returns a meta object associated with this component, containing information such as the component's path and source file. It will be a Mason::Component::InstanceMeta object if called on a component instance, and a Mason::Component::ClassMeta object if called on a component class; the former contains slightly more information.
my $path = $self->cmeta->path;
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.