PET::Filter::UtilXmlMap |
This filter is used to map xml-like tags to PET::Util method calls. For example <foo:bar a=”1” b=subst.x /> can be mapped to [% Util.foo.bar(‘a’,’1’,’b’,subst.x) %]
You can actually create a full website using tags only. See the “preprocess” method for available syntax.
| PET:: | This filter is used to map xml-like tags to PET::Util method calls. |
| Functions | |
| preprocess ($file, $content) | This is a (chainable) Filter module that maps XML-like tags to UTIL calls. |
| _processTag ($util, $method, $params, $cont) | This gets an “XML tag” that we have to process. |
| _parseParams ($s, $body) | Raw string int the tag, that must be parsed. |
sub preprocess
This is a (chainable) Filter module that maps XML-like tags to UTIL calls.
E.g. <foo:bar a=”1” b=subst.id /> is transformed to [% Util.foo.bar (‘a’,’1’,’b’,subst.id) %]
Basically if you put this module in the filter chain, you will be able to call methods on loaded Util classes which accept one hash as a parameter.
When an XML tag is used as a container tag, the body of the container is passed as parameter _body to the method. E.g. <foo:bar>zoh</foo:bar> will call [% Util.foo.bar(‘_body’,’zoh’) %]
Note : as Util ($UTIL) is already defined when the filter is run, we can check if a) the named Util exists b) the named method exists.
There also are some special uses (basically syntax sugar) :
<foo:bar.field a=”1” ... /> is translated to : [% GET Util.foo.bar(‘a’,’1’).field %]
<foo:bar=var a=”1” ... /> is translated to : [% SET var = Util.foo.bar(‘a’,’1’) %]
<foo:bar parameter1 parameter2 a=”b” ... /> Note that this practice is not recommended.
ALso note that usually the best thing is to make this filter the last in the chain.
<:=foo /> After this “tag”, “foo” will becoma your default tag, so that <:bar /> wil be equivalent to <foo:bar />.
sub _processTag
This gets an “XML tag” that we have to process.
| $util | util name (see <PET::Util>), first part before the colon in the tag |
| $method | second part (right after the colon) in the tag (think $util:$method) |
| $params | parameters in a string; that is, everything remaining in the tag |
| $cont | is the body of the tag if this is not a “processing instruction” |
The tag to substitute in. This checks $Util, so if there is no such method, we do not process the tag.
This is a (chainable) Filter module that maps XML-like tags to UTIL calls.
sub preprocess
This gets an “XML tag” that we have to process.
sub _processTag
Raw string int the tag, that must be parsed.
sub _parseParams