Perl 5 implementation of the Garden functional template language (abandoned.)
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Garden: A Functional Template Engine (Perl 5 implementation)

Garden is the name of a Template language I am designing, and plan to develop
several implementations in various programming languages.

It is inspired by StringTemplate (Java) with many influences from my own
Flower XML engine (Perl 6), which itself was inspired by TAL/METAL.

Templates written for one version of Garden should work in any implementation.

This Perl 5 implementation is the first, and is considered the reference
implementation of the specification. In fact, the specification was developed
in conjunction with this implementation.

Read the spec at

See the tests for better examples, but here's a quick one:

In './templates/testTemplate.tmpl':

  testTemplate (name, users) {{
  Hello [[name]], how are you?
  [[users.count]] users said hi:
  [[users:userList(*name, *opts)]]
  userList (name, opts) {{
    * [[name]]: [[opts.roles:userRoles(*role); sep=", "]] [[?opts.leader:Leader()]]

  userRoles (role) {{ #[[userRoles.number]] [[role]] }}

  Leader () {{ -- Is a team leader. }}

In './':

  use Garden;
  my $garden = Garden->new(paths=>['./templates']);
  my $test   = $garden->get("testTemplate");
  my $data   = {
    name  => "World",
    users => {
      Bob    => { roles => ['user'],          leader => 0 },
      Kevin  => { roles => ['user','admin'],  leader => 0 },
      Joe    => { roles => ['user','tester'], leader => 1 },
  say $test->render($data);

Should print the following text:

  Hello World, how are you?
  3 users said hi:
    * Bob: #1 user
    * Joe: #1 user, #2 tester -- Is a team leader.
    * Kevin: #1 user, #2 admin

If you are wondering why the names are in a different order, it's because
in Perl, hashes return results unsorted. We're sorting the keys by name.

Oh, and a lot of the syntax such as the {{, }}, [[, ]], etc. is configurable,
on a per file basis, so if you want different markers, it's easy to change
them. The defaults are used above.

That shows off a few features, but there's plenty more in the tests.

Author: Timothy Totten
License: Artistic License 2.0