Skip Menu |
 

This queue is for tickets about the XML-LibXML CPAN distribution.

Report information
The Basics
Id: 84267
Status: new
Priority: 0/
Queue: XML-LibXML

People
Owner: Nobody in particular
Requestors: mywolfson [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Documentation for XPathContext::registerVarLookupFunc is incorrect
Date: Thu, 28 Mar 2013 13:22:31 -0400
To: bug-XML-LibXML [...] rt.cpan.org
From: Misha Wolfson <mywolfson [...] gmail.com>
Download (untitled) / with headers
text/plain 2.1k
*Current State* The documentation says: Variables <https://metacpan.org/module/XML::LibXML::XPathContext#___pod> This example demonstrates registerVarLookup() method. We use XPath variables to recycle results of previous evaluations: sub var_lookup { *my ($varname,$ns,$data)=@_;* return $data->{$varname}; } my $areas = XML::LibXML->new->parse_file('areas.xml'); my $empl = XML::LibXML->new->parse_file('employees.xml'); my $xc = XML::LibXML::XPathContext->new($empl); my %variables = ( A => $xc->find('/employees/employee[@salary>10000]'), B => $areas->find('/areas/area[district='Brooklyn']/street'), ); # get names of employees from $A working in an area listed in $B $xc->registerVarLookupFunc(\&var_lookup, \%variables); my @nodes = $xc->findnodes('$A[work_area/street = $B]/name'); and registerVarLookupFunc $xpc->registerVarLookupFunc($callback, $data) Registers variable lookup function *$prefix*. The registered function is executed by the XPath engine each time an XPath variable is evaluated. It takes three arguments: $data, variable name, and variable ns-URI and must return one value: a number or string or any XML::LibXML:: object that can be a result of findnodes: Boolean, Literal, Number, Node (e.g. Document, Element, etc.), or NodeList. For convenience, simple (non-blessed) array references containing only XML::LibXML::Node<https://metacpan.org/module/XML::LibXML::Node> objects can be used instead of an XML::LibXML::NodeList<https://metacpan.org/module/XML::LibXML::NodeList> . * * *Problems* - The var_lookup function is wrong in the example is wrong. It should take args in the order ($data, $name, $uri) as this unit test<https://bitbucket.org/shlomif/perl-xml-libxml/src/bc0878287d05/t/32xpc_variables.t?at=XML-LibXML-1.72> shows. This is incredibly confusing to users. - The description for registerVarLookupFunc uses the variable $prefix, rather than $callback, which is also incorrect and confusing. However, the order of args described here is correct. This confusion makes the otherwise brilliant library much more difficult to use and learn. Please help future users suffer less than I did. Thanks! -- Misha
Download (untitled) / with headers
text/html 63.9k

Message body is not shown because it is too large.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.