1. Shlomi Fish
  2. perl-XML-LibXML

Pull requests

#14 Declined
Repository
p5-xml-libxml
Branch
default
Repository
perl-XML-LibXML
Branch
default

New improved hash deref for XML::LibXML::Element

Author
  1. Toby Inkster
Reviewers
Description

OK, here's an improved version.

Firstly, I've dropped the array deref, as I have no rationale for including it.

Secondly, MANIFEST and Changes are now updated; documentation is included in XML::LibXML::AttributeHash (which is where the bulk of the new implementation is).

The new implementation uses Tie::Hash and Hash::FieldHash, making the dereferenced hash fully usable for read-write access to the element's attributes. So you can get/set, can check "exists" on keys, iterate through them, etc.

The primary rationale for this is that when using a DOM in most other languages, attributes can be accessed in a manner similar to this. For example, in Javascript:

var links = document.getElementsByTagName('a');
window.alert(links[0].href);

The patch allows Perl code to function similarly:

my @links = $document->getElementsByTagName('a');
warn $links[0]{'href'};

The one drawback is that the implementation requires Hash::FieldHash, thus adding an extra non-core dependency. However, Hash::FieldHash is very lightweight (an XS module with no non-core dependencies) and reliable (776 PASSes on CPAN testers, with just one FAIL).

Also included are a bunch of whitespace improvements for LibXML.pm (mostly removing tabs).

  • Learn about pull requests

Comments (0)