Pod::Abstract::Path(3pm) | User Contributed Perl Documentation | Pod::Abstract::Path(3pm) |
Pod::Abstract::Path - Search for POD nodes matching a path within a document tree.
/head1(1)/head2 # All head2 elements under # the 2nd head1 element //item # All items anywhere //item[@label =~ {^\*$}] # All items with '*' labels. //head2[/hilight] # All head2 elements containing # "hilight" elements # Top level head1s containing head2s that have headings matching # "NAME", and also have at least one list somewhere in their # contents. /head1[/head2[@heading =~ {NAME}]][//over] # Top level headings having the same title as the following heading. /head1[@heading = >>@heading] # Top level headings containing at least one subheading with the same # name. /head1[@heading = ./head2@heading]
Pod::Abstract::Path is a path selection syntax that allows fast and easy traversal of Pod::Abstract documents. While it has a simple syntax, there is significant complexity in the queries that you can create.
Not all of the designed features have yet been implemented, but it is currently quite useful, and all of the filters in "paf" make use of Pod Paths.
If you want to evaluate an expression from a node as though it were the root node, the easiest ways are to detach or dup it - otherwise the root operator will find the original root node.
Names together separated by spaces will match all of those names - e.g: "//head1 over" will match all lists and all head1s.
Expressions can be:
Optionally, the right hand closing brace may have the "i" modifier to cause case-insensitive matching. i.e "[@heading =~ {foo}i]" will match "foo" or "fOO".
The following Perl compatible operators are supported:
String: " eq gt lt le ge ne "
Numeric: "== < > <= >= !="
Pod::Abstract::Path is not designed to be fast. It is designed to be expressive and useful, but it involves sucessive expand/de-duplicate/linear search operations and doing this with large documents containing many nodes is not suitable for high performance systems.
Simple expressions can be fast enough, but there is nothing to stop you from writing "//[<condition>]" and linear-searching all 10,000 nodes of your Pod document. Use with caution in interactive systems.
It is recommended you use the "<Pod::Abstract::Node-"select>> method to evaluate Path expressions.
If you wish to generate paths for use in other modules, use "parse_path" to generate a parse tree, pass that as an argument to "new", then use "process" to evaluate the expression against a list of nodes. You can re-use the same parse tree to process multiple lists of nodes in this fashion.
It is possible during processing - especially using ^ or .. operators - to generate many duplicate matches of the same nodes. Each pass around the loop, we filter to unique nodes so that duplicates cannot inflate more than one time.
This effectively means that "//^" (however awful that is) will match one node only - just really inefficiently.
Parse a list of lexemes and generate a driver tree for the process method. This is a simple recursive descent parser with one element of lookahead.
Ben Lilburne <bnej@mac.com>
Copyright (C) 2009 Ben Lilburne
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2020-05-17 | perl v5.30.0 |