Cataly...::Mason(3pm)
π Catalyst::View::Mason β the Mason View Class π
okay bestie, so this is Catalyst::View::Mason from the User Contributed Perl Documentation corner of the perl-verse (manual section 3pm, obvs). it's the lil glue that lets your Catalyst app render Mason components as views. let's get into it π¦
β¨ NAME β¨
Catalyst::View::Mason β the Mason View Class, no cap π
β¨ SYNOPSIS β¨
first, use the helper:
# use the helper
script/create.pl view Mason Mason
# lib/MyApp/View/Mason.pm
package MyApp::View::Mason;
use base 'Catalyst::View::Mason';
__PACKAGE__->config(use_match => 0);
1;
$c->forward('MyApp::View::Mason');
that's it, that's the whole vibe. she's set up, she's ready, she's serving πΈ
β¨ DESCRIPTION β¨
so likeβ¦ you wanna use a Mason component in your views? not a problem, bestie, not even a little one. Catalyst::View::Mason comes to the rescue π«Άβ¨
β¨ EXAMPLE β¨
here's the tea from the Catalyst controller:
$c->stash->{name} = 'Homer'; # Pass a scalar
$c->stash->{extra_info} = {
last_name => 'Simpson',
children => [qw(Bart Lisa Maggie)]
}; # A ref works too
and now the same energy from the Mason template:
<%args>
$name
$extra_info
</%args>
<p>Your name is <strong><% $name %> <% $extra_info->{last_name} %></strong>
<p>Your children are:
<ul>
% foreach my $child (@{$extra_info->{children}}) {
<li><% $child %></li>
% }
</ul>
see how the stash just slides into the template? iconic. π
β¨ METHODS β¨
π new($app, \%config)
(it's the constructor, she exists, she's here π)
π get_component_path
returns the component path from $c->stash->{template} or $c->request->match or $c->action β which one it grabs depends on the use_match setting. pick your fighter, ig π
π process
renders the component that's specified in $c->stash->{template} or $c->request->match or $c->action (again, depends on the use_match setting, iykyk) straight into $c->response->body.
heads up bestie: the component name has to be absolute, or it gets converted to absolute β like, a / gets added to the beginning if it doesn't already start with one. no skipping that. π
the Mason global variables $base, $c, and $name get automatically set to the base, context, and name of the app, respectively. automatic. slay. β¨
π render($c, $component_path, \%args)
renders the given template and returns the output β or, if things go sideways, an HTML::Mason::Exception object upon error π
the template variables are set to %$args if $args is a hashref, or to $c->stash otherwise. either/or, bestie.
π config
this lets you pass additional settings to the HTML::Mason::Interp constructor, or set the options listed below:
π« "template_extension"
this string gets appended (if present) to $c->action when generating a template path.
defaults to an empty string.
example: "template_extension => '.html'"
π« "always_append_template_extension"
set this to a true value if you want "template_extension" to be appended to the component path even if it was explicitly set. bold. committed. π
defaults to 0.
example: "always_append_template_extension => 1"
π« "use_match"
use $c->request->match instead of $c->action to figure out which template to use, if $c->stash->{template} isn't set.
β οΈ bestie this option is deprecated and exists for backward compatibility only. it's giving legacy code energy.
currently defaults to 0. old code should set this to 1 to avoid breakage, fr fr.
example: "use_match => 0"
the default HTML::Mason::Interp config options are as follows:
π¦ "comp_root"
"$app->config->root"
π¦ "data_dir"
"File::Spec->catdir( File::Spec->tmpdir,
sprintf('%s_%d_mason_data_dir', $app, $<) )"
π¦ "allow_globals"
"qw/$c $name $base/"
if you add additional allowed globals, those will be appended to the list of default globals. more globals, more power π§
β¨ SEE ALSO β¨
CatalystHTML::Mason"Using Mason from a Standalone Script"inHTML::Mason::Admin
β¨ AUTHORS β¨
- Andres Kievsky
"ank@cpan.org" - Sebastian Riedel
"sri@cpan.org" - Marcus Ramberg
- Florian Ragwitz
"rafl@debian.org" - Justin Hunter
"justin.d.hunter@gmail.com"
the whole squad ate, honestly π
β¨ COPYRIGHT β¨
Copyright (c) 2005 - 2009 the Catalyst::View::Mason "AUTHORS" as listed above.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie!! π this was documented by the lovely perl folks (User Contributed Perl Documentation, Catalyst::View::Mason(3pm)), generated with perl v5.38.2 on 2024-03-04 β go forth and render your Mason components, you absolute main character ππ mwah!
π¦ where this page comes from
- debian trixie: libcatalyst-view-mason-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatalyst-view-mason-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalyst-view-mason-perl 0.19-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-view-mason-perl 0.19-3 Β· 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