NAME

Catalyst::View::Mason - Mason View Class

SYNOPSIS

    # 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->{DEBUG} = 'all';
    __PACKAGE__->config->{comp_root} = '/path/to/comp_root';
    __PACKAGE__->config->{data_dir} = '/path/to/data_dir';

    1;

    $c->forward('MyApp::View::Mason');

DESCRIPTION

Want to use a Mason component in your views? No problem! Catalyst::View::Mason comes to the rescue.

EXAMPLE

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

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
        % }
        </ul>

CAVEATS

You have to define comp_root and data_dir. If comp_root is not directly defined within config, the value comes from $c->config->{root}. If you don't define it at all, Mason is going to complain :) The default data_dir is /tmp.

METHODS

process

Renders the component specified in $c->stash->{template} or $c->request->match to $c->response->body.

Note that the component name must be absolute, or is converted to absolute (i.e., a / is added to the beginning if it doesn't start with one).

Mason global variables $base, $c, and c<$name> are automatically set to the base, context, and name of the app, respectively.

config

This allows your view subclass to pass additional settings to the Mason HTML::Mason::Interp->new constructor.

SEE ALSO

Catalyst, HTML::Mason, "Using Mason from a Standalone Script" in HTML::Mason::Admin

AUTHOR

Andres Kievsky ank@cpan.org Sebastian Riedel sri@cpan.org Marcus Ramberg

COPYRIGHT

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.