XML::LibXML::LazyMatcher - A simple XML matcher with lazy evaluation.
Version 0.02
my $dom = XML::LibXML->load_xml (string => "<root><c1><c2>hello</c2><c3>world</c3></c1></root>"); my $matcher; my ($c2content, $c3content); { package XML::LibXML::LazyMatcher; $matcher = M (root => C (M (c1 => C (M (c2 => sub { $c2content = $_[0]->textContent; return 1; }), M (c3 => sub { $c3content = $_[0]->textContent; return 1; }))))); } $matcher->($dom->documentElement);
None.
Returns a matcher function. This returned function takes an XML::LibXML::Node object as an argument. First, The matcher checks if the tag name of the passed node is correct, then, applies the node to all sub_matchers. If all sub_matchers return true value then the M() returns 1. Otherwise returns 0.
sub_matcher
M()
You can define some action as a sub_matcher. A typical sub_matcher may be like this:
sub { my $node = shift; # $node should be a XML::LibXML::Node. return 0 unless is_valid($node); do_some_action($node); return 1; }
Creates a matcher function which tests all child nodes. If a sub_matcher returns true value, then the C() returns 1. Otherwise returns 0.
C()
Creates a matcher function which test all child nodes sequentially. Every child nodes is tested by the appropriate sub_matcher accordingly. The returned matcher fails if one of sub_matchers fails.
Also, this matcher ignores empty text node for convenience.
Toru Hisai, <toru at torus.jp>
<toru at torus.jp>
Please report any bugs or feature requests to bug-xml-libxml-lazymatcher at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-LibXML-LazyMatcher. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-xml-libxml-lazymatcher at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc XML::LibXML::LazyMatcher
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-LibXML-LazyMatcher
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/XML-LibXML-LazyMatcher
CPAN Ratings
http://cpanratings.perl.org/d/XML-LibXML-LazyMatcher
Search CPAN
http://search.cpan.org/dist/XML-LibXML-LazyMatcher/
Copyright 2010 Toru Hisai.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install XML::LibXML::LazyMatcher, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::LibXML::LazyMatcher
CPAN shell
perl -MCPAN -e shell install XML::LibXML::LazyMatcher
For more information on module installation, please visit the detailed CPAN module installation guide.