By adding support for this dot notation to HTML::Template, the programmers' job of sending data to the template is easier, and designers have easier access to more data to display in the template, without learning any more tag syntax.

The dot notation allows you to pass arguments to method calls (as in the my_date.dmy('/') example above). In fact, you can pass other objects in the template as well, and this enables more complex usage. Imagine we had a (fictional) Formatter object which could perform some basic string formatting functions. This could be used in e.g. currencies, or dates.

As of version 0.94, the dot notation is also supported on TMPL_LOOP tags (but see the "LIMITATIONS" section).

Given an object method (or a hash key) that returns an array or a reference to an array, we will unwrap that array for use in the loop. Individual array elements are mapped to a hash { 'this' => $elt }, so that you can refer to them in TMPL_VARs as "this.something".

An example might help. Let's use the canonical Class::DBI example for our data. Suppose you have an $artist object, which has_many CDs. You can now pass just the $artist object, and handle the loops in the template:

Casing of parameter names follows the option case_sensitive of HTML::Template. If you do not use that option, all parameter names are converted to lower case. I suggest turning this option on to avoid confusion.

Quotes and spaces

Because of the way HTML::Template parses parameter names (which follows the rules of HTML attributes), you have to be careful when your expressions contain spaces or quote characters. You can say <tmpl_var something.without.spaces>, but not <tmpl_var something with spaces>. You can use single or double quotes around your entire expression, and then use the other one inside: <tmpl_var name="some.method('with arguments')"> This is the recommended way to write your expressions.

(Note: within expressions, the characters in [`'"] are recognised as quote characters. So if you need to pass literal quotes to a method, you could do it like this: <tmpl_var name='some.method(`need a " here`)'>. )

No attempt to even measure performance has been made. For now the focus is on usability and stability. If you carry out benchmarks, or have suggestions for performance improvements, be sure to let us know!