NAME

Catalyst::View::HTML::Mason - HTML::Mason rendering for Catalyst

SYNOPSIS

package MyApp::View::Mason;

use Moose;
use namespace::autoclean;

extends 'Catalyst::View::HTML::Mason';

__PACKAGE__->config(
    interp_args => {
        comp_root => MyApp->path_to('root'),
    },
);

1;

DESCRIPTION

This module provides rendering of HTML::Mason templates for Catalyst applications.

It's basically a rewrite of Catalyst::View::Mason, which became increasingly hard to maintain over time, while keeping backward compatibility.

ATTRIBUTES

interp

The mason interpreter instance responsible for rendering templates.

interp_class

The class the interp instance is constructed from. Defaults to HTML::Mason::Interp.

interp_args

Arguments to be passed to the construction of interp. Defaults to an empty hash reference.

template_extension

File extension to be appended to every component file. By default it's only appended if no explicit component file has been provided in $ctx->stash->{template}.

always_append_template_extension

If this is set to a true value, template_extension will also be appended to component paths provided in $ctx->stash->{template}.

encoding

Encode Mason output with the given encoding. Can be a string encoding name (which will be resolved using Encode::find_encoding()), or an Encode::Encoding object. See Encode::Supported for a list of encodings.

NOTE Starting in Catalyst v5.90080 we encode text like body responses as UTF8 automatically. In some cases templates that did not declare an encoding previously will now need to. In general I find setting this to 'UTF-8' is a forward looking approach.

globals

An array reference specifying globals to be made available in components. Empty by default.

Each global specification may be either a plain string containing a variable name, or an array reference consisting of a variable name and a callback.

When using the array-reference form, the provided callback will be used to generate the value of the global for each request. The callback will be invoked with the view instance as well as the current request context.

When specifying plain strings, the value will be generated by looking up the variable name minus the sigil in $ctx->stash.

Examples:

globals => [ '$foo', '%bar' ],

globals => '$baz',

globals => [
  ['$ctx',         sub { $_[1] }       ],
  ['$current_user, sub { $_[1]->user } ],
],

Would export $foo and %bar to every Mason component as globals using identically-named values in the stash, similar to:

our $foo = $ctx->stash->{foo};
our %bar = %{ $ctx->stash->{bar} };

METHODS

render($ctx, $component, \%args)

Renders the given component and returns its output.

A hash of template variables may be provided in $args. If $args isn't given, template variables will be taken from $ctx->stash.

A NOTE ABOUT DHANDLERS

Note that this view does not support automatic dispatching to Mason dhandlers. Dhandlers can still be used, but they must be referred to explicitly like any other component.

AUTHORS

  • Florian Ragwitz <rafl@debian.org>

  • Sebastian Willert <willert@cpan.org>

  • Robert Buels <rbuels@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Florian Ragwitz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.