++ed by:
1 non-PAUSE user
Author image Zahatski Aliaksandr
and 1 contributors


Plosurin - Perl 5 implementation of Closure Templates


For template example.soy with content:

    {namespace mytest}
      * Simple test
    {template .Hello}
    <h1>Foreach example</h1>
    {foreach $a in [1,2]}
        <p>Line: {$a}</p><br/>

To get Perl 5 module (MyApp, for example), just run the following command:

        plosurin.p5 -package MyApp < example.soy > MyApp.pm

Use template in your Perl 5 program:

        use MyApp;
        print &MyApp::mytest_Hello();

or get help:

         perldoc MyApp.pm


Plosurin - Perl implementation of Closure Templates.

Template Structure

Every Soy file should have these components, in this order:

  • A namespace declaration.

  • One or more template definitions.

Here is an example template:

  {namespace examples.simple}
   * Says hello to a person.
   * @param name The name of the person to say hello to.
  {template .helloName}
    Hello {$name}!

Command Syntax

Commands are instructions that you give the template compiler to create templates and add custom logic to templates. Put commands within Closure Template tags, which are delimited by braces ({}).

The first token within a tag is the command name (the print command is implied if no command is specified), and the rest of the text within the tag (if any) is referred to as the command text. Within the template you can enclose other commands to evaluate conditional expressions, iterate over data objects, or print messages.

 {if length($items) > 5}
 {msg desc="Says hello to the user."}

If a command has a corresponding end command, then the end command's name is a / followed by the name of the start command, e.g. foreach and /foreach.


Return array of tempaltes

Perl 5 code generator API

    use Plosurin;
    my $p = new Plosurin::;
    my $in_fd = new IO::File:: "< $infile" or die "$infile: $!";
    my $nodes = $p->parse( $in, "file_name.soy");
    say $p->as_perl5( { package => "MyApp::Templates" }, $nodes );

as_perl5 { package=>"MyApp::Tmpl" }, $node1[, $noden]

Export nodes as perl5 package


Closure Templates Documentation http://code.google.com/closure/templates/docs/overview.html

Perl 6 implementation https://github.com/zag/plosurin


Zahatski Aliaksandr, <zag@cpan.org>


Copyright (C) 2011 by Zahatski Aliaksandr

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