PrePAN

Sign in to PrePAN

XML::LibXML::Ferry Marshall LibXML nodes and native objects

Good

Synopsis

# There's quite a lot in the POD, but the simplest example of ferry() per se would be:

use XML::LibXML;
use XML::LibXML::Ferry;

my $hashref = {
  foo => undef,
  bar => undef,
};
my $doc = XML::LibXML->load_xml(location => 'something.xml');
# Document contains Foo, Bar and Baz elements, each containing straight text.
$doc->documentElement->ferry($hash, {
  # foo and bar are implicit
});
# $hashref->{foo} now contains the text inside <Foo/>, same for Bar, and Baz is ignored.

Description

This along with XML::LibXML::Proxy is my intro to contributing in the CPAN. For the name, like for Proxy I have cleared it with Shlomi Fish, the current maintainer of XML::LibXML, so that part's OK.

This adds a few convenience methods to XML::LibXML::Element, mostly "ferry()" which greatly simplifies the process of marshaling data from Libxml into a native structure of Perl objects/hashes of one's choosing. My upcoming business-related modules depend on this to succinctly express the relationship between its objects and the XML structure it relates to, in "to_node()/from_node()" methods throughout.

This ferry() simplifies traversing and flattening XML structures, into hashes and/or object instances with setter methods.

Also included are helper functions attr(), create() and add() to help creating XML structures.

Test coverage's 100%, so I think I'm all set to upload.

Comments

Please sign up to post a review.