Data-DPath
view release on metacpan or search on metacpan
lib/Data/DPath.pm view on Meta::CPAN
Elements in XML always have an order which is in contrast to hash keys
in Perl.
XML elements names on same level can be repeated, not so in hashes.
XML element names are more limited than arbitrary strange hash keys.
XML elements can have attributes and those can be addressed by XPath;
Perl data structures do not need this. On the other side, data
structures in Perl can contain blessed elements, DPath can address
this.
XML has namespaces, data structures have not.
Arrays starting with index 1 as in XPath would be confusing to read
for data structures.
DPath allows filter expressions that are in fact just Perl expressions
not an own sub language as in XPath.
=head2 Comparison with Data::Path
There is a similar approach on CPAN, L<Data::Path|Data::Path>. Here is
a comparison matrix between L<Data::Path|Data::Path> and
L<Data::DPath|Data::DPath>.
(Warning: B<alpha> grade comparison ahead, not yet fully verified,
only evaluated by reading the source. Speed comparison not really
benchmarked.)
---------------------------------------------------------------------
Criteria Data::Path Data::DPath
---------------------------------------------------------------------
real XPath syntax no no
---------------------------------------------------------------------
allow strange, YES YES
non-xml but
perl-like although
hash keys limited,
see next
---------------------------------------------------------------------
allows special no YES
chars of own
path syntax in you can quote everything
hash keys
("/[]|*.")
---------------------------------------------------------------------
call subs in YES no
data structure,
like:
/method()
---------------------------------------------------------------------
callbacks on YES no
not found keys
---------------------------------------------------------------------
element "//" no YES
for "ANYWHERE"
(//foo/bar)
---------------------------------------------------------------------
element "." no YES
for "NOSTEP" or
"actual position"
(/.[filter expr])
---------------------------------------------------------------------
element ".." no YES
for "PARENT"
(//foo/..)
---------------------------------------------------------------------
element "::ancestor" no YES
for "ANCESTOR"
(//foo/::ancestor)
---------------------------------------------------------------------
element no YES
"::ancestor-or-self"
---------------------------------------------------------------------
element "*" no YES
for "ANYSTEP" or
"all subelements"
(/foo/*)
---------------------------------------------------------------------
array access YES YES
like /foo[4]
although including negative indexes
limited and whitespace awareness
---------------------------------------------------------------------
complex no YES
filter expressions
like full Perl expressions
/foo[size == 3] or plus sugar functions
/.[isa("Foo::Bar")]
---------------------------------------------------------------------
works with YES YES
blessed subelements
---------------------------------------------------------------------
( run in 0.479 second using v1.01-cache-2.11-cpan-39bf76dae61 )