Re: What would you like to see in XML::LibXML ?
Shlomi Fish <[email protected]> Mon, 30 Jan 2012 14:09:18 +0200
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 30 Jan 2012 11:38:44 +0000 Tim Brody <[email protected]> wrote: > 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". > I don't like this approach too much. It raises many problems, and while being relatively easy to implement, I would prefer to give the user the option to annotate the node either with one datum or (preferably) with several named values (stored in a «string => string» hash). That will be, given sufficient support from libxml2 (like a freeing-callback), more flexible, powerful and safer. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Rethinking CPAN - http://shlom.in/rethinking-cpan Larry Wall dreams in Perl. Please reply to list if it's a mailing list post - http://shlom.in/reply . _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs