Template::Alloy::Velocity - Velocity (VTL) role
The Template::Alloy::Velocity role provides the syntax and the interface for the Velocity Templating Language (VTL). It also brings many of the features from the various templating systems.
See the Template::Alloy documentation for configuration and other parameters.
The following documents have more information about the velocity language.
Add language usage and samples.
Used bh the parse_tree method when SYNTAX is set to 'velocity'.
Similar to process_simple, but with syntax set to velocity.
The magic Java Velocity property lookups don't exist. You must use the actual method name, Alloy will not try to guess it for you. Java Velocity allows you to type $object.Attribute and Java Velocity will look for the Attribute, getAttribute, getattribute, isAttribute methods. In Perl Alloy, you can call $object.can('Attribute') to introspect the object.
Escaping of variables is consistent. The Java Velocity spec is not. The velocity spec says that "\\$email" will return "\\$email" if email is not defined and it will return "\foo" if email is equal to "foo". The slash behavior magically changes according to the spec. In Alloy the "\\$email" would be "\$email" if email is not defined.
You can set items to null (undefined) in Alloy. According to the Java Velocity reference-guide you have to configure Velocity to do this. To get the other behavior, you would need to do "#if($questionable)#set($foo=$questionable)#end". The default Velocity spec way provides no way for checking null return values.
There currently isn't a "literal" directive. The VTL reference-guide doesn't mention #literal, but the user-guide does. In Alloy you can use the following:
#get('#foreach($a in [1..3]) $a #end')
We will probably add the literal support - but it will still have to parse the document, so unless you are using compile_perl, you will parse literal sections multiple times.
There is no "$velocityCount" . Use "$loop.count" .
In Alloy, excess whitespace outside of the directive matters. In the VTL user-guide it mentions that all excess whitespace is gobbled up. Alloy supports the TT chomp operators. These operators are placed just inside the open and close parenthesis of directives as in the following:
#set(~ $a = 1 ~)
In Alloy, division using "/" is always floating point. If you want integer division, use "div". In Java Velocity, "/" division is integer only if both numbers are integers.
Perl doesn't support negative ranges. However, arrays do have the reverse method.
#foreach( $bar in [-2 .. 2].reverse ) $bar #end
In Alloy arguments to macros are passed by value, not by name. This is easy to achieve with alloy - simply encase your arguments in single quotes and then eval the argument inside the macro. The velocity people claim this feature as a jealously guarded feature. My first template system "WrapEx" had the same feature. It happened as an accident. It represents lazy software architecture and is difficult to optimize.
Paul Seamons <email@example.com>
This module may be distributed under the same terms as Perl itself.
To install Template::Alloy, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.