AxKit2
view release on metacpan or search on metacpan
lib/AxKit2/XSP/TaglibHelper.pm view on Meta::CPAN
For functions that return arrays of strings, use the indicated wrapper
tag for the list items instead of <funcname>-item
=item forcearray
For functions that always return an array, you should generally set
this option to "1". the reason is that if your array-returning function
only returns one value in its array, the result won't be treated as an
array otherwise.
=item conditional
The function's return value will not be printed, and instead will be
used to conditionally execute child tags. NOTE that arguments to the
function cannot be brought in via child tags, but instead must come in
via attributes.
=item isreally
This function specification is actually an alias for a perl function of
a different name. For example, a specification of
C<"person($name):isreally=get_person"> allows you to have a tag <ns:person
name="Joe"/> that will resolve to Perl code "get_person('Joe')".
=item as_xml
Set this to true and return a well-balanced chunk of XML, and it will be
parsed and added to the output.
=item array_uses_hash
Set this to true to use the preceding hash key as the prefix to
array tag names. In the situation where complex data structures of
hashes pointing to arrays are returned, then this makes the xml output
more meaningful. Otherwise the default of the itemtag or <funcname>-item
is used.
=back
=head1 EXAMPLE
if you had these two functions:
sub hello ($) {
my ($name) = @_;
return "Hello, $name!";
}
sub get_person ($) {
my ($name) = @_;
return {
person => {
name => $name,
age => 25,
height => 200,
}
}
}
...and you called them with this xsp fragment:
<test:hello>
<test:name>Joe</test:name>
</test:hello>
<test:get-person name="Bob"/>
...you would get this XML result:
Hello, Joe!
<person>
<height>200</height>
<age>25</age>
<name>Bob</name></person>
If your function returned deeper result trees, with hashes containing
hashrefs or something similar, that would be handled fine. There are some
limitations with arrays, however, described in the BUGS AND LIMITATIONS
section.
=head1 STRUCTURED INPUT EXAMPLE
If you wish to send structured data (i.e. not just a scalar) to a taglib
function, use "*" instead of "$" for a variable. The input to a taglib
function specified as "insert_person($pid,*extra)" might be:
<test:insert-person pid="123">
<test:extra>
<weight>123</weight>
<friends>
<pid>3</pid>
<pid>5</pid>
<pid>13</pid>
</friends>
</test:extra>
</test:insert-person>
The function call would be the same as:
insert_function("123", {
weight => 123,
friends => [ 3, 5, 13 ]
}
);
The <friends> container holds repeating tags, notice, and TaglibHelper
figured out automatically that it needs to use an arrayref instead of
hashref for the values. But you'll get unexpected results if you mix
repeating tags and nonrepeating ones:
<test:extra>
<weight>123</weight>
<friend>3</friend>
<friend>5</friend>
<friend>13</friend>
</test:extra>
Just wrap your singular repeated tags with a plural-form tag, in this
case <friends>.
( run in 1.513 second using v1.01-cache-2.11-cpan-364913b4093 )