Note that the xslate engine is not aware of context, so all the methods and filters/functions return a single value, even when the equivalent of Perl's returns a list of values.
Note that optional functions are defined in Text::Xslate::Bridge::Star.
"$arrayref.first()"
Returns the first element of $arrayref.
"$arrayref.last()"
Returns the last element of $arrayref.
"$arrayref.size()"
Returns the number of elements in $arrayref.
"$arrayref.join($separator)"
Joins the elements of $arrayref into a single string separated by $separator.
"$arrayref.reverse()"
Returns an ARRAY reference consisting of the elements of $arrayref in the opposite order.
"$arrayref.sort(?$callback)"
Sorts $arrayref and returns a new ARRAY reference. The optional $callback is the same as Perl's.
Examples:
: my $arrayref = [2, 1, 10]; : # alphabetic sort (default) : $arrayref.sort().join(" "); # 1 10 2 : # explicitly alphabetic : $arrayref.sort(-> $a, $b { $a cmp $b }).join(" "); # 1 10 2 : # numeric sort : $arrayref.sort(-> $a, $b { $a <=> $b }).join(" "); # 1 2 10
See also ``sort'' in perlfunc.
"$arrayref.map($callback)"
Evaluates $callback for each element of $arrayref and returns a new ARRAY reference composed of the result of each such evaluation.
Examples:
: my $arrayref = [1, 2, 4, 8, 16]; : # double : $arrayref.map(-> $a { $a * 2 }).join(','); # 2,4,8,16,32 : # sequence : my $hashref = {a => 1, b => 2, c => 3, d => 4}; : ['b', 'd', 'a'].map(-> $a {$hashref[$a]}).join(','); # 2,4,1
See also ``map'' in perlfunc
"$arrayref.reduce($callback)"
Reduces $arrayref by calling $callback multiple times. If $arrayref is empty, this method returns "nil".
Examples:
: my $arrayref = [10, 20, 30]; : # sum : $arrayref.reduce(-> $a, $b { $a + $b }); # 60 : # concat : $arrayref.reduce(-> $a, $b { $a ~ $b }); # 102030 : # min : $arrayref.reduce(-> $a, $b { $a min $b }); # 10 : # max : $arrayref.reduce(-> $a, $b { $a max $b }); # 30
See also ``reduce'' in List::Util.
"$arrayref.merge($v)"
Returns a new ARRAY reference consisting of $arrayref and $v.
$v may be an ARRAY reference or a scalar value.
"$hashref.size()"
Returns the number of entries of $hashref.
: my $hashref = {a => 1, b => 2, c => 3, d => 4}; : $hashref.size(); # 4
"$hashref.keys()"
Returns an ARRAY reference consisting of the keys of $hashref, which are sorted by the keys.
: my $hashref = {a => 1, b => 2, c => 3, d => 4}; : $hashref.keys().join(' '); # a b c d
"$hashref.values()"
Returns an ARRAY reference consisting of the values of $hashref, which are sorted by the keys.
: my $hashref = {a => 1, b => 2, c => 3, d => 4}; : $hashref.values().join(' '); # 1 2 3 4
"$hashref.kv()"
Returns an ARRAY reference consisting of the key-value pairs of $hashref, which are sorted by the keys. Each pair is an object that has the "keys" and "value" attributes.
For example:
: for $hashref.kv() -> $pair { <: $pair.key :>=<: $pair.value :> : }
Output:
a=1 b=2 c=3 d=4
"$hashref.merge($v)"
Returns a new HASH reference consisting of $hashref and $v.
: my $hashref = {a => 1, b => 2, c => 3, d => 4}; : my $new = $hashref.merge({a => 0, e => 5}); : # {a => 0, b => 2, c => 3, d => 4, e => 5}
See also ``Loops'' in Text::Xslate::Syntax::Kolon and ``Loops'' in Text::Xslate::Syntax::TTerse.
For example:
: for $arrayref -> $item { <: $~item.cycle('odd', 'even') :> : }
It will print "odd even odd even ...".
This is aliased to "first" in TTerse for compatibility with TT2.
This is aliased to "last" in TTerse for compatibility with TT2.
For example, the following two statements are the same:
<: $value | foo :> <: foo($value) :>
Note that some builtin functions, such as "defined", are not a real function which you cannot use as a filter.
"raw" is an alias to "mark_raw".
The html meta characters are "/[<>"'&]/".
"html" is an alias to "html_escape".
The unsafe URI characters are characters not included in the "unreserved" character class defined by RFC 3986, i.e. "/[^A-Za-z0-9\-\._~]/".
"uri" is an alias to "uri_escape".
This function is provided for testing and debugging.
Text::Xslate::Manual
Text::Xslate::Bridge::Star