.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Template::Alloy::Operator 3pm" .TH Template::Alloy::Operator 3pm "2013-08-23" "perl v5.18.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Template::Alloy::Operator \- Operator role. .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Template::Alloy::Operator role provides the regexes necessary for Template::Alloy::Parse to parse operators and place them in their appropriate precedence. It also provides the play_operator method which is used by Template::Alloy::Play and Template::Alloy::Compile for playing out the stored operator ASTs. .SH "ROLE METHODS" .IX Header "ROLE METHODS" .IP "play_operator" 4 .IX Item "play_operator" Takes an operator \s-1AST\s0 in the form of .Sp .Vb 1 \& [undef, \*(Aq+\*(Aq, 1, 2] .Ve .Sp Essentially, all operators are stored in \s-1RPN\s0 notation with a leading \*(L"undef\*(R" to disambiguate operators in a normal Alloy expression \s-1AST.\s0 .IP "define_operator" 4 .IX Item "define_operator" Used for defining new operators. .Sp See Template::Alloy for more details. .SH "OPERATOR LIST" .IX Header "OPERATOR LIST" The following operators are available in Template::Alloy. Except where noted these are the same operators available in \s-1TT. \s0 They are listed in the order of their precedence (the higher the precedence the tighter it binds). .ie n .IP """.""" 4 .el .IP "\f(CW.\fR" 4 .IX Item "." The dot operator. Allows for accessing sub-members, methods, or virtual methods of nested data structures. .Sp .Vb 1 \& my $obj\->process(\e$content, {a => {b => [0, {c => [34, 57]}]}}, \e$output); \& \& [% a.b.1.c.0 %] => 34 .Ve .Sp Note: on access to hashrefs, any hash keys that match the sub key name will be used before a virtual method of the same name. For example if a passed hash contained pair with a keyname \*(L"defined\*(R" and a value of \&\*(L"2\*(R", then any calls to hash.defined(another_keyname) would always return 2 rather than using the vmethod named \*(L"defined.\*(R" To get around this limitation use the \*(L"|\*(R" operator (listed next). Also \- on objects the \*(L".\*(R" will always try and call the method by that name. To always call the vmethod \- use \*(L"|\*(R". .ie n .IP """|""" 4 .el .IP "\f(CW|\fR" 4 .IX Item "|" The pipe operator. Similar to the dot operator. Allows for explicit calling of virtual methods and filters (filters are \*(L"merged\*(R" with virtual methods in Template::Alloy and \s-1TT3\s0) when accessing hashrefs and objects. See the note for the \*(L".\*(R" operator. .Sp The pipe character is similar to \s-1TT2\s0 in that it can be used in place of a directive as an alias for \s-1FILTER. \s0 It similar to \s-1TT3\s0 in that it can be used for virtual method access. This duality is one source of difference between Template::Alloy and \s-1TT2\s0 compatibility. Templates that have directives that end with a variable name that then use the \&\*(L"|\*(R" directive to apply a filter will be broken as the \*(L"|\*(R" will be applied to the variable name. .Sp The following two cases will do the same thing. .Sp .Vb 1 \& [% foo | html %] \& \& [% foo FILTER html %] .Ve .Sp Though they do the same thing, internally, foo|html is stored as a single variable while \*(L"foo \s-1FILTER\s0 html\*(R" is stored as the variable foo which is then passed to the \s-1FILTER\s0 html. .Sp A \s-1TT2\s0 sample that would break in Template::Alloy or \s-1TT3\s0 is: .Sp .Vb 1 \& [% PROCESS foo a = b | html %] .Ve .Sp Under \s-1TT2\s0 the content returned by \*(L"\s-1PROCESS\s0 foo a = b\*(R" would all be passed to the html filter. Under Template::Alloy and \s-1TT3,\s0 b would be passed to the html filter before assigning it to the variable \*(L"a\*(R" before the template foo was processed. .Sp A simple fix is to do any of the following: .Sp .Vb 1 \& [% PROCESS foo a = b FILTER html %] \& \& [% | html %][% PROCESS foo a = b %][% END %] \& \& [% FILTER html %][% PROCESS foo a = b %][% END %] .Ve .Sp This shouldn't be too much hardship and offers the great return of disambiguating virtual method access. .ie n .IP """\e""" 4 .el .IP "\f(CW\e\fR" 4 .IX Item "" Unary. The reference operator. Not well publicized in \s-1TT. \s0 Stores a reference to a variable for use later. Can also be used to \*(L"alias\*(R" long names. .Sp .Vb 1 \& [% f = 7 ; foo = \ef ; f = 8 ; foo %] => 8 \& \& [% foo = \ef.g.h.i.j.k; f.g.h.i.j.k = 7; foo %] => 7 \& \& [% f = "abcd"; foo = \ef.replace("ab", "\-AB\-") ; foo %] => \-AB\-cd \& \& [% f = "abcd"; foo = \ef.replace("bc") ; foo("\-BC\-") %] => a\-BC\-d \& \& [% f = "abcd"; foo = \ef.replace ; foo("cd", "\-CD\-") %] => ab\-CD\- .Ve .ie n .IP """++ \-\-""" 4 .el .IP "\f(CW++ \-\-\fR" 4 .IX Item "++ --" Pre and post increment and decrement. My be used as either a prefix or postfix operator. .Sp .Vb 1 \& [% ++a %][% ++a %] => 12 \& \& [% a++ %][% a++ %] => 01 \& \& [% \-\-a %][% \-\-a %] => \-1\-2 \& \& [% a\-\- %][% a\-\- %] => 0\-1 .Ve .ie n .IP """** ^ pow""" 4 .el .IP "\f(CW** ^ pow\fR" 4 .IX Item "** ^ pow" Right associative binary. X raised to the Y power. This isn't available in \s-1TT 2.15.\s0 .Sp .Vb 1 \& [% 2 ** 3 %] => 8 .Ve .ie n .IP """!""" 4 .el .IP "\f(CW!\fR" 4 .IX Item "!" Prefix not. Negation of the value. .ie n .IP """\-""" 4 .el .IP "\f(CW\-\fR" 4 .IX Item "-" Prefix minus. Returns the value multiplied by \-1. .Sp .Vb 1 \& [% a = 1 ; b = \-a ; b %] => \-1 .Ve .ie n .IP """*""" 4 .el .IP "\f(CW*\fR" 4 .IX Item "*" Left associative binary. Multiplication. .ie n .IP """/ div DIV""" 4 .el .IP "\f(CW/ div DIV\fR" 4 .IX Item "/ div DIV" Left associative binary. Division. Note that / is floating point division, but div and \&\s-1DIV\s0 are integer division. .Sp .Vb 2 \& [% 10 / 4 %] => 2.5 \& [% 10 div 4 %] => 2 .Ve .ie n .IP """% mod MOD""" 4 .el .IP "\f(CW% mod MOD\fR" 4 .IX Item "% mod MOD" Left associative binary. Modulus. .Sp .Vb 1 \& [% 15 % 8 %] => 7 .Ve .ie n .IP """+""" 4 .el .IP "\f(CW+\fR" 4 .IX Item "+" Left associative binary. Addition. .ie n .IP """\-""" 4 .el .IP "\f(CW\-\fR" 4 .IX Item "-" Left associative binary. Minus. .ie n .IP """_ ~""" 4 .el .IP "\f(CW_ ~\fR" 4 .IX Item "_ ~" Left associative binary. String concatenation. .Sp .Vb 1 \& [% "a" ~ "b" %] => ab .Ve .ie n .IP """< > <= >=""" 4 .el .IP "\f(CW< > <= >=\fR" 4 .IX Item "< > <= >=" Non associative binary. Numerical comparators. .ie n .IP """lt gt le ge""" 4 .el .IP "\f(CWlt gt le ge\fR" 4 .IX Item "lt gt le ge" Non associative binary. String comparators. .ie n .IP """eq""" 4 .el .IP "\f(CWeq\fR" 4 .IX Item "eq" Non associative binary. String equality test. .ie n .IP """==""" 4 .el .IP "\f(CW==\fR" 4 .IX Item "==" Non associative binary. In \s-1TT\s0 syntaxes the V2EQUALS configuration item defaults to true which means this operator will operate the same as the \*(L"eq\*(R" operator. Setting V2EQUALS to 0 will change this operator to mean numeric equality. You could also use [% ! (a <=> b) %] but that is a bit messy. .Sp The HTML::Template syntaxes default V2EQUALS to 0 which means that it will test for numeric equality just as you would normally expect. .Sp In either case \- you should always use \*(L"eq\*(R" when you mean \*(L"eq\*(R". The V2EQUALS will most likely eventually default to 0. .ie n .IP """ne""" 4 .el .IP "\f(CWne\fR" 4 .IX Item "ne" Non associative binary. String non-equality test. .ie n .IP """!=""" 4 .el .IP "\f(CW!=\fR" 4 .IX Item "!=" Non associative binary. In \s-1TT\s0 syntaxes the V2EQUALS configuration item defaults to true which means this operator will operate the same as the \*(L"ne\*(R" operator. Setting V2EQUALS to 0 will change this operator to mean numeric non-equality. You could also use [% (a <=> b) %] but that is a bit messy. .Sp The HTML::Template syntaxes default V2EQUALS to 0 which means that it will test for numeric non-equality just as you would normally expect. .Sp In either case \- you should always use \*(L"ne\*(R" when you mean \*(L"ne\*(R". The V2EQUALS will most likely eventually default to 0. .ie n .IP """<=>""" 4 .el .IP "\f(CW<=>\fR" 4 .IX Item "<=>" Non associative binary. Numeric comparison operator. Returns \-1 if the first argument is less than the second, 0 if they are equal, and 1 if the first argument is greater. .ie n .IP """cmp""" 4 .el .IP "\f(CWcmp\fR" 4 .IX Item "cmp" Non associative binary. String comparison operator. Returns \-1 if the first argument is less than the second, 0 if they are equal, and 1 if the first argument is greater. .ie n .IP """&&""" 4 .el .IP "\f(CW&&\fR" 4 .IX Item "&&" Left associative binary. And. All values must be true. If all values are true, the last value is returned as the truth value. .Sp .Vb 1 \& [% 2 && 3 && 4 %] => 4 .Ve .ie n .IP """||""" 4 .el .IP "\f(CW||\fR" 4 .IX Item "||" Right associative binary. Or. The first true value is returned. .Sp .Vb 1 \& [% 0 || \*(Aq\*(Aq || 7 %] => 7 .Ve .Sp Note: perl is left associative on this operator \- but it doesn't matter because || has its own precedence level. Setting it to right allows for Alloy to short circuit earlier in the expression optree (left is (((1,2), 3), 4) while right is (1, (2, (3, 4))). .ie n .IP """//""" 4 .el .IP "\f(CW//\fR" 4 .IX Item "//" Right associative binary. Perl 6 err. The first defined value is returned. .Sp .Vb 1 \& [% foo // bar %] .Ve .ie n .IP """..""" 4 .el .IP "\f(CW..\fR" 4 .IX Item ".." Non associative binary. Range creator. Returns an arrayref containing the values between and including the first and last arguments. .Sp .Vb 1 \& [% t = [1 .. 5] %] => variable t contains an array with 1,2,3,4, and 5 .Ve .Sp It is possible to place multiple ranges in the same [] constructor. This is not available in \s-1TT.\s0 .Sp .Vb 1 \& [% t = [1..3, 6..8] %] => variable t contains an array with 1,2,3,6,7,8 .Ve .Sp The .. operator is the only operator that returns a list of items. .ie n .IP """? :""" 4 .el .IP "\f(CW? :\fR" 4 .IX Item "? :" Ternary \- right associative. Can be nested with other ?: pairs. .Sp .Vb 2 \& [% 1 ? 2 : 3 %] => 2 \& [% 0 ? 2 : 3 %] => 3 .Ve .ie n .IP """*= += \-= /= **= %= ~=""" 4 .el .IP "\f(CW*= += \-= /= **= %= ~=\fR" 4 .IX Item "*= += -= /= **= %= ~=" Self-modifying assignment \- right associative. Sets the left hand side to the operation of the left hand side and right (clear as mud). In order to not conflict with \s-1SET, FOREACH\s0 and other operations, this operator is only available in parenthesis. .Sp .Vb 2 \& [% a = 2 %][% a += 3 %] \-\-\- [% a %] => \-\-\- 5 # is handled by SET \& [% a = 2 %][% (a += 3) %] \-\-\- [% a %] => 5 \-\-\- 5 .Ve .ie n .IP """=""" 4 .el .IP "\f(CW=\fR" 4 .IX Item "=" Assignment \- right associative. Sets the left-hand side to the value of the righthand side. In order to not conflict with \s-1SET, FOREACH\s0 and other operations, this operator is only available in parenthesis. Returns the value of the righthand side. .Sp .Vb 2 \& [% a = 1 %] \-\-\- [% a %] => \-\-\- 1 # is handled by SET \& [% (a = 1) %] \-\-\- [% a %] => 1 \-\-\- 1 .Ve .ie n .IP """not NOT""" 4 .el .IP "\f(CWnot NOT\fR" 4 .IX Item "not NOT" Prefix. Lower precedence version of the '!' operator. .ie n .IP """and AND""" 4 .el .IP "\f(CWand AND\fR" 4 .IX Item "and AND" Left associative. Lower precedence version of the '&&' operator. .ie n .IP """or OR""" 4 .el .IP "\f(CWor OR\fR" 4 .IX Item "or OR" Right associative. Lower precedence version of the '||' operator. .ie n .IP """err ERR""" 4 .el .IP "\f(CWerr ERR\fR" 4 .IX Item "err ERR" Right associative. Lower precedence version of the '//' operator. .ie n .IP """\->"" (Not in \s-1TT2\s0)" 4 .el .IP "\f(CW\->\fR (Not in \s-1TT2\s0)" 4 .IX Item "-> (Not in TT2)" Macro operator. Works like the \s-1MACRO\s0 directive but can be used in map, sort, and grep list operations. Syntax is based on the Perl 6 pointy sub. There are two differences from the \s-1MACRO\s0 directive. First is that if no argument list is specified, a default argument list with a single parameter named \*(L"this\*(R" will be used. Second, the \f(CW\*(C`\->\*(C'\fR operator parses its block as if it was already in a template tag. .Sp .Vb 4 \& [% foo = \->{ "Hi" } %][% foo %] => Hi \& [% foo = \->{ this.repeat(2) } %][% foo("Hi") %] => HiHi \& [% foo = \->(n){ n.repeat(2) } %][% foo("Hi") %] => HiHi \& [% foo = \->(a,b){ a; "|"; b } %][% foo(2,3) %] => 2|3 \& \& [% [0..10].grep(\->{ this % 2 }).join %] => 1 3 5 7 9 \& [% [\*(Aqa\*(Aq..\*(Aqc\*(Aq].map(\->{ this.upper }).join %] => A B C \& \& [% [1,2,3].sort(\->(a,b){ b <=> a }).join %] prints 3 2 1 \& \& [% c = [{k => "wow"}, {k => "wee"}, {k => "a"}] %] \& [% c.sort(\->(a,b){ a.k cmp b.k }).map(\->{this.k}).join %] => a wee wow .Ve .Sp Note: Care should be used when attempting to sort large lists. The mini-language of Template::Alloy is a interpreted language running in Perl which is an interpreted language. There are likely to be performance issues when trying to do low level functions such as sort on large lists. .Sp The \s-1RETURN\s0 directive and return item, list, and hash vmethods can be used to return more interesting values from a \s-1MACRO.\s0 .Sp .Vb 3 \& [% a = \->(n){ [1..n].return } %] \& [% a(3).join %] => 1 2 3 \& [% a(10).join %] => 1 2 3 4 5 6 7 8 9 10 .Ve .Sp The Schwartzian transform is now possible in Template::Alloy (somebody somewhere is rolling over in their grave). .Sp .Vb 5 \& [%\- qw(Z a b D y M) \& .map(\->{ [this.lc, this].return }) \& .sort(\->(a,b){a.0 cmp b.0}) \& .map(\->{this.1}) \& .join %] => a b D M y Z .Ve .ie n .IP """{}""" 4 .el .IP "\f(CW{}\fR" 4 .IX Item "{}" This operator is not exposed for external use. It is used internally by Template::Alloy to delay the creation of a hash until the execution of the compiled template. .ie n .IP """[]""" 4 .el .IP "\f(CW[]\fR" 4 .IX Item "[]" This operator is not exposed for external use. It is used internally by Template::Alloy to delay the creation of an array until the execution of the compiled template. .ie n .IP """@()""" 4 .el .IP "\f(CW@()\fR" 4 .IX Item "@()" List context specifier. Methods or functions inside this operator will always be called in list context and will always return an arrayref of the results. See the \s-1CALL_CONTEXT\s0 configuration directive. .ie n .IP """$()""" 4 .el .IP "\f(CW$()\fR" 4 .IX Item "$()" Item context specifier. Methods or functions inside this operator will always be called in item (scalar) context. See the \s-1CALL_CONTEXT\s0 configuration directive. .ie n .IP """qr""" 4 .el .IP "\f(CWqr\fR" 4 .IX Item "qr" This operator is not exposed for external use. It is used internally by Template::Alloy to store a regular expression and its options. It will return a compiled Regexp object when compiled. .ie n .IP """\-temp\-""" 4 .el .IP "\f(CW\-temp\-\fR" 4 .IX Item "-temp-" This operator is not exposed for external use. It is used internally by some directives to pass temporary, literal data into play_expr to allow additional vmethods or filters to be called on existing data. .SH "AUTHOR" .IX Header "AUTHOR" Paul Seamons .SH "LICENSE" .IX Header "LICENSE" This module may be distributed under the same terms as Perl itself.