Re: What would you like to see in XML::LibXML ?
Tim Brody <[email protected]> Mon, 30 Jan 2012 11:38:44 +0000
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <EMEW3|ac868893e7d30486c47f3d469ded8211o0YBck04tdb2|ecs.soton.ac.uk|[email protected]> |
On Sun, 2012-01-29 at 22:11 +0200, Shlomi Fish wrote: > Hi Aaron, > > On Sun, 29 Jan 2012 14:49:36 +0000 > Aaron Crane <[email protected]> wrote: > > > Shlomi Fish <[email protected]> wrote: > > I'd particularly value the ability to annotate a node with a Perl > > scalar, and retrieve that scalar later — much like the per-node > > `_private` data in libxml2, but accessible to Perl code. Straw-man > > API: > > [snip] > Yes, it would be very tricky. One option to overcome this may be to make these > annotations be “tokens” which are arbitrary perl strings or numbers, but not > arbitrary perl scalars. The XML-LibXML programmer will be able to map or > unpack these tokens into something more complex, but it would be their > responsibility to allocate unique tokens and to free their resources later. > > We can potentially make these annotations be dictionaries mapping «strings => > strings» (using perl's built-in hashes, or balanced binary trees or whatever), > but I guess we can stop there. > > I guess that would be the case of a leaky abstraction (see > http://en.wikipedia.org/wiki/Leaky_abstraction , http://www.joelonsoftware.com/articles/LeakyAbstractions.html ) > or a quirky abstraction (see http://shlomif-tech.livejournal.com/49510.html ), > but if it makes our life easier…. What if we overloaded the node stringification to return the memory address of the libxml node instead of the Perl scalar? use overload '"' => sub { sprintf("%s(0x%x)", ref($_[0]), $_[0]->_addr) }; Where _addr returns the pointer address of the *libxml* node (not proxy). Which, I think, would allow this to work: $SLOW_STUFF{$node} = { ... }; This would need a big health warning about the difference between ref($node) and "$node". /Tim. _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs