Re: What would you like to see in XML::LibXML ?
Tim Brody <[email protected]> Mon, 30 Jan 2012 13:16:08 +0000
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <EMEW3|05aa8c76f2a3273d671542afeacde3ffo0YDG904tdb2|ecs.soton.ac.uk|[email protected]> |
On Mon, 2012-01-30 at 14:09 +0200, Shlomi Fish wrote: > 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. What problems does it raise? I'm unsure about adding (non-DOM) annotations to LibXML, when the more robust approach for storing contextual data is using a hash of object-references: $INFO{$obj1} = "foo"; $INFO{$obj2} = "bar"; The trouble with LibXML is it breaks that Perlish approach. All the best, Tim. _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs