Data::DPath::Parser - Parses the DPath subset used by Data::DPath
SYNOPSIS
use Data::DPath::Parser;
my $result = Data::DPath::Parser->parse( $xpath );
$result -> evaluate( $root, $context );
$sub = $result -> compile;
$sub -> ( $root, $context );
DESCRIPTION
Some notes on the parsing and evaluation:
Result Objects
TODO: change to return sets of references into the data tree
The result expressions alway return true or false. For DPath expressions that would normally return a node-set, the result is true if the current SAX event would build a node that would be in the node set. No floating point or string return objects are supported (this may change).
Context
The DPath context node is the document root.
Not sure what to do about the context position, but the context size is of necessity undefined.
DPath Expressions
DPath is based on XPath, but has some subtle (or not-so-subtle) differences.
Axis
DPath makes use of the following axis:
- ancestor
- ancestor-or-self
- attribute
-
Eventually (with Perl 6), we will be able to support arbitrary attributes tied to data objects. But until then, only the following attributes are supported:
- can
-
Example: //*[@can="print" and @can="read"]
This will find all the nodes that have
print
andread
methods. - defined
-
Example: /foo[@defined]
Returns the object
foo
in the root of the context if it is defined. - isa
-
Example: //*[@isa="Apache::Upload"]
This will find all the nodes in the context that are Apache::Upload objects.
- size
- version
- child
-
This forces the identifier to be a child of a node. A child may be a hash key or an array index, depending on the parent node type. It will not be a method.
- descendant
- descendant-or-self
- following
- following-sibling
- method
-
This forces the identifier to be a method of an object.
- namespace
- parent
- preceding
- preceding-sibling
- self