Cataly...::Mason(3pm)

πŸ“¦
version 0.19 Β· 5 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 ✨

  • Catalyst
  • HTML::Mason
  • "Using Mason from a Standalone Script" in HTML::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 (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