NAME

XML::LibXML::LazyMatcher - A simple XML matcher with lazy evaluation.

VERSION

Version 0.02

SYNOPSIS

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

EXPORT

None.

SUBROUTINES/METHODS

M (tagname => [sub_matcher, ...])

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.

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;
}

C (sub_matcher, ...)

Creates a matcher function which tests all child nodes. If a sub_matcher returns true value, then the C() returns 1. Otherwise returns 0.

S (sub_matcher, ...)

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.

AUTHOR

Toru Hisai, <toru at torus.jp>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc XML::LibXML::LazyMatcher

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

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.