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).
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> <h2>&yatt:x;</h2> <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 MyYATT::EntNS->render_(...)
.
package MyYATT::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.