mirod / xmltwig

XML, the Perl way
http://xmltwig.org/xmltwig/
33 stars 19 forks source link

Subroutine sort redefined at [...]/XML/XPath/NodeSet.pm line 31. #38

Open pileswasp opened 3 years ago

pileswasp commented 3 years ago

Hello,

The monkey patching at https://github.com/mirod/xmltwig/blob/master/Twig/XPath.pm#L20 only silences warnings in one direction.

If XML::XPath::NodeSet is use()d first all is silent, if XML::Twig::XPath is used first XML::XPath::NodeSet reinstates its orignal version of the sort method.

Test case:

$ perl -MXML::Twig::XPath -MXML::XPath -e 1
Subroutine sort redefined at /usr/local/share/perl/5.22.1/XML/XPath/NodeSet.pm line 31.
$ perl -MXML::XPath -MXML::Twig::XPath -e 1

version_info.txt

The "fix" for the warning is to make sure XML::XPath::NodeSet is use()d before applying the monkey patch. The fix for the reason for the warning is presumably to change the monkey patching to sub-classing.

I'm assuming the same applies to XML::XPathEngine::NodeSet, but I haven't tested that far.

Pull request to follow (hopefully).

pileswasp commented 3 years ago

Addendum: The above test case requires that you have both XML::XPathEngine and XML::XPath installed (XML::Twig::XPath uses XML::XPathEngine by preference, but monkey patches both by default).