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;

A Template may also contain components which are reusable blocks of template functionality and which refer to other Catalyst Views in your application:

    <view-master title='Homepage'>
      <view-header navbar_section='home'/>
        <section>
          <p>You are doomed to discover you can never recover from the narcolyptic
          country in which you once stood, where the fires alway burning but there's
          never enough wood</p>
        </section>
      <view-footer copyright='$.copy' />
    </view-master>

Such components can wrap your main content or even other component, and they can accept arguments. See Catalyst::View::Template::Lace::Tutorial for more details.

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 with existing views since there is no contract beween a view and the controller that is calling it. For example a typo in setting the stash can turn into a hard to track down bug in the template. 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 this 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.