xmltwig icon indicating copy to clipboard operation
xmltwig copied to clipboard

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

Open pileswasp opened this issue 4 years ago • 1 comments

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 avatar Dec 11 '20 07:12 pileswasp

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

pileswasp avatar Dec 13 '20 11:12 pileswasp