The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::View::Template::Lace - Catalyst View Adaptor for Template::Lace

SYNOPSIS

Define a View:

package  MyApp::View::User;

use Moo;
extends 'Catalyst::View::Template::Lace';

has [qw/age name motto/] => (is=>'ro', required=>1);

sub template {q[
  <html>
    <head>
      <title>User Info</title>
    </head>
    <body>
      <dl id='user'>
        <dt>Name</dt>
        <dd id='name'>NAME</dd>
        <dt>Age</dt>
        <dd id='age'>AGE</dd>
        <dt>Motto</dt>
        <dd id='motto'>MOTTO</dd>
      </dl>
    </body>
  </html>
]}

sub process_dom {
  my ($self, $dom) = @_;
  $dom->dl('#user', +{
   age=>$self->age,
   name=>$self->name,
   motto=>$self->motto});
}

1;

Used in a controller:

package MyApp::Controller::User;

use Moose;
use MooseX::MethodAttributes;
extends 'Catalyst::Controller';

sub display :Path('') {
  my ($self, $c) = @_;
  $c->view('User',
    name => 'John',
    age => 42,
    motto => 'Why Not?')
  ->http_ok;
}

__PACKAGE__->meta->make_immutable;

DESCRIPTION

NOTE I consider this an early access release. Code and API here is subject to significant change as needed to advance the project. Please don't use this in production unless you are willing to cope with that.

Catalyst::View::Template::Lace is a view adaptor for Template::Lace with some Catalyst specific helpers and features added. Reviewing documentation for Template::Lace would useful in furthering your ability to use it in Catalyst.

In short, this is a template framework for Catalyst that introduces strongly typed views and view components as design patterns for your web applications. What this means is that unlike most Catalyst views that you're probably familiar with (such as the Template::Toolkit view) we define one view per template instead of one view for all the templates. Although this might seem like a lot of views to write the upside is by defining a strong interface for your view, you eliminate a host of display errors that I commonly see in the wild since there is no contract beween a view and the controller that is calling it. Also since each component in your view has access to the Catalyst context, you can write smarter views with display logic properly encapsulated near the template code it will actually be used. This reduces complexity in your controllers and makes it easier to solve complex layout logic.

After reviewing these documentation you can advance to Catalyst::View::Template::Lace::Tutorial and you might find the test cases in the /t directory of this distribution handy as well.

NOTE I consider current documentation to be the 'thin red line' requirement for CPAN publication but there's tons more to be done. Critique and contributions very welcomed!.

CONFIGURATION

This component defines the following configuration options:

factory

These specifies which subclass of Template::Lace::Factory will be used to manage your view lifecycle. The default is Catalyst::View::Template::Lace::Factory. You can also specify Catalyst::View::Template::Lace::PerContext or write your own. See documentation for the two options for more.

model_class

render_class

init_args

model_constructor

component_handlers

All these are pass through configuration to the underlying subclass of Template::Lace::Factory which you should review.

AUTHOR

John Napiorkowski email:jjnapiork@cpan.org

SEE ALSO

Template::Lace, Catalyst::View::Template::Pure

COPYRIGHT & LICENSE

Copyright 2017, John Napiorkowski email:jjnapiork@cpan.org

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