XML::LibXML::QuerySelector - add querySelector and querySelectorAll methods to XML::LibXML nodes
use XML::LibXML::QuerySelector; my $document = XML::LibXML->load_xml(location => 'my.xhtml'); my $warning = $document->querySelector('p.warning strong'); print $warning->toString if defined $warning;
This module defines a class (it has no constructor so perhaps closer to an abstract class or a role) XML::LibXML::QuerySelector, and sets itself up as a superclass (not a subclass) of XML::LibXML::Document, XML::LibXML::DocumentFragment and XML::LibXML::Element, thus making its methods available to objects of those classes.
Yes, this is effectively monkey-patching, but it's performed in a relatively safe manner.
The methods provided by this module are defined in the W3C Recomendation "Selectors API Level 1" http://www.w3.org/TR/selectors-api/.
Given a CSS selector, returns the first match or undef if there are no matches.
Given a CSS selector, returns all matches as a list, or if called in scalar context, as an XML::LibXML::NodeList.
querySelectorAllreturns a static node list; not a live node list. (Called on a document or document fragment, it will return a live node list as specified in the W3C Recommendation.)
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=XML-LibXML-QuerySelector.
Toby Inkster <firstname.lastname@example.org>.
This software is copyright (c) 2012-2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.