Text::Xslate::Manual::Builtin - Online Linux Manual PageSection : 3pm
Updated : 2020-11-09
Source : perl v5.32.0
Note : User Contributed Perl Documentation

NAMEText::Xslate::Manual::Builtin − Builtin methods and filters/functions in Xslate

DESCRIPTIONThis document describes builtin methods and filters/functions in Xslate. 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.

METHODSThe xslate engine supports auto-boxing, so you can call methods for primitive (non-object) values. The following are builtin methods.

For nilnil has its specific namespace as nil, although no builtin methods are provided.

For SCALARsThe namespace of SCALARs is scalar, although no builtin methods are provided.

For ARRAY referencesThe namespace of ARRAY references is array. $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):().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.

For HASH referencesThe namespace of HASH references is hash. $hashref.size() Returns the number of entries of $hashref. ​ : my $hashref = {a => 1, b => 2, c => 3, d => 4}; ​ :(); # 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}; ​ :().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}; ​ :().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} $v must be a HASH reference.

LOOP VARIABLESYou can use special loop variables in for loops, although its forms vary in template syntaxes, i.e. $~item in Kolon and loop in TTerse. In this list, the name of the loop variable is represented as $~item. See also Loops in Text::Xslate::Syntax::Kolon and Loops in Text::Xslate::Syntax::TTerse.

$~item / $~item.indexThe current iterating index in the loop, which starts 0.

$~item.countThe current iterating count in the loop, which starts 1. i.e. the same as $~item + 1.

$~item.cycle(...)Selects a value in the arguments in cycle. For example: ​ : for $arrayref −> $item {<: $~item.cycle('odd', 'even') :> ​ : } It will print odd even odd even ....

$~item.is_firstTrue if the loop block is the first, false otherwise. This is aliased to first in TTerse for compatibility with TT2.

$~item.is_lastTrue if the loop block is the last, false otherwise. This is aliased to last in TTerse for compatibility with TT2.

$~item.peek_nextThe next item of the looping array. nil if is_last. i.e. the same as $~item.is_last ? nil : $~item.body[$~item+1].

$~item.peek_prevThe previous item of the looping array. nil if is_first. i.e. the same as $~item.is_first ? nil : $~item.body[$~item−1].

$~item.bodyThe reference of the looping array.

$~item.sizeThe size of the looping array. i.e. scalar(@{$arrayref}) in Perl.

$~item.max_indexThe maximum index of the looping array. i.e. $#{$arrayref} in Perl.

FILTERS/FUNCTIONSThe xslate engine supports filter syntax as well as function call. The following is the builtin functions, which can be invoked as filter syntax. 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.

mark_raw($str)Mark $str as a raw string to avoid auto HTML escaping. You'd better avoid to use this function. Instead, you should use the ​mark_raw() subroutine in programs, which you can import from ​Text::Xslate::Util. raw is an alias to mark_raw.

unmark_raw($str)Remove the raw mark from $str. If $str is not a raw string, this function returns $str as is.

html_escape($str)Escapes html meta characters in $str. If $str is a raw string, this function returns $str as is. The html meta characters are /[<>"'&]/. html is an alias to html_escape.

uri_escape($str)Escapes unsafe URI characters in $str which gets encoded to UTF−8. 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.

is_array_ref(($value)Returns true if $value is an ARRAY reference.

is_hash_ref(($value)Returns true if $value is a HASH reference.

dump($value)Inspects $value with Data::Dumper. This function is provided for testing and debugging.

defined($value)Returns true if $value is defined. This is not a real function, but an unary operator, so you can omit the parens like defined $value.

SEE ALSOText::Xslate Text::Xslate::Manual Text::Xslate::Bridge::Star
0
Johanes Gumabo
Data Size   :   44,862 byte
man-Text::Xslate::Manual::Builtin.3pmBuild   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   5 / 200,746
Visitor ID   :     :  
Visitor IP   :   3.15.15.91   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|249|Text::Xslate::Manual::Builtin.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|Text::Xslate::Manual::Builtin.3pm|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|249|Text::Xslate::Manual::Builtin.3pm|43|br══─}─══|'br══─}─══ )         (htmlprn|149|Text::Xslate::Manual::Builtin.3pm|43|'br══─}─══ |'br══─}─══ )