View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
KOBAYASHI, Hiroaki > YATT-Lite > prog_guide


Annotate this POD


Open  1
View/Report Bugs
Source   Latest Release: YATT-Lite-0.101_001


prog_guide -- programmer's guide for YATT


YATT consists of two layers. General purpose template engine "YATT::Lite", and sample Web Application Framework "WebMVC0".

Note: In this document, I choose simplicity of explanation over accuracy. Some methods/configs are described in subclass section as-if it is defined there (but actually not).

YATT::Lite -- General Purpose Template Engine ^

When requested, yatt converts a template into a set of perl functions and compile them. After successful compilation, yatt calls corresponding function. For example, assume we have a variable $template_1 which contains a template like following:

  <!yatt:args x y>
  <yatt:hello who=y />

  <!yatt:widget hello who>
  Hello &yatt:who;!

And our program is like following:

  use YATT::Lite;
  my $yatt = new YATT::Lite(vfs => [data => $template_1]);
  print $yatt->render('', {x => "foo", y => "bar"});
  # ..Or..
  $yatt->render_into(\*STDOUT, "" => {x => "baz", y => "qux"});

Then, when $yatt->render is called, yatt generates following perl script (package) and invoke it as MyApp::EntNS->render_(...).

  package MyApp::EntNS;
  sub render_ {
    my ($this, $CON, $x, $y, $body) = @_;
    print $CON (q|<h2>|, YATT::Lite::Util::escape($x), q|</h2>|, "\n");
    $this->render_hello($CON, (undef, $y)[1, 0]); print $CON ("\n");}
  sub render_hello {
    my ($this, $CON, $who, $body) = @_;
    print $CON (q|Hello |, YATT::Lite::Util::escape($who), q|!|, "\n");}

Note: if you specify template as a file, it is cached until the file is modified.

syntax highlighting: