PET::Filter::UtilXmlMap

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.

Summary
PET::Filter::UtilXmlMapThis 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.

Functions

preprocess ($file, $content)

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’) %]

You can also use the followin “relaxed” format for passing parameters

<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.

You can also use the following special construct

<:=foo /> After this “tag”, “foo” will becoma your default tag, so that <:bar /> wil be equivalent to <foo:bar />.

_processTag ($util, $method, $params, $cont)

sub _processTag

This gets an “XML tag” that we have to process.

Parameters

$utilutil name (see <PET::Util>), first part before the colon in the tag
$methodsecond part (right after the colon) in the tag (think $util:$method)
$paramsparameters in a string; that is, everything remaining in the tag
$contis the body of the tag if this is not a “processing instruction”

Returns

The tag to substitute in.  This checks $Util, so if there is no such method, we do not process the tag.

_parseParams ($s, $body)

sub _parseParams

Raw string int the tag, that must be parsed.  Returns a string that can be substituted.  $body is substituted as parameter “_body”.

Base class for all Filter modules.
sub preprocess
This is a (chainable) Filter module that maps XML-like tags to UTIL calls.
sub _processTag
This gets an “XML tag” that we have to process.
sub _parseParams
Raw string int the tag, that must be parsed.
Close