Re: [Parseperl-discuss] PPI + Storable = ?
Brought to you by:
adamkennedy
From: Adam K. <ad...@ph...> - 2005-07-08 08:25:09
|
Yes. PPI uses a weakref-based tree system. Although the objects themselves are built using a normal non-recursive=20 structure, they look UP the tree by using the %PPI::Element::PARENT=20 hash, which contains a weak reference to their parent Node keyed by the=20 Scalar::Util::refaddr of the child object. There's an entry in PARENT for every single child Element object. So far as I'm aware, this is pretty much the ideal way of implementing=20 trees structures in Perl. It's fast as hell (and faster once we get a XS=20 version in PPI::XS), is completely immune from circular reference leaks,=20 and it even cleans itself properly when PPI::Document objects are=20 destroyed. It also handily makes everything look like plain trees in the=20 debugger. The DESTROY method for each element cleans up it's entry in PARENT,=20 keeping the hash from exploding in size. However, whenever you manipulate PDOM tree you have to keep the PARENT=20 refs up to date. Most of the time this is done for you transparently. Take a look at the implementation of PPI::Document::clone. It does a fast Clone::clone, and then walk the PDOM tree relinking all=20 of the children to the parents in the cloned copy. In order to make PPI::Documents natively Storable-friendly, we probably=20 need a Storable Hook method to do the same sort of relinking process=20 when we thaw out the document. Write me a quick 17_storable.t test script (just copy one of the other=20 smaller test scripts) and attach it to a rt.cpan.org bug report, and=20 I'll handle the implementation for you. I probably should refactor that=20 bit a little anyway so it uses the same code as ->clone. Adam K Johan Lindstr=F6m wrote: > I'm trying to cache parsed PPI::Document objects by serializing them=20 > with Storable, but I see strange things. The objects before/after look=20 > the same, but e.g. a $node->statement doesn't work with the thawed obje= ct. >=20 > Is there any known reason it wouldn't "just work" to freeze/thaw a=20 > PPI::Document with it's nodes etc? >=20 >=20 > /J >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by the 'Do More With Dual!' webinar=20 > happening > July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dua= l > core and dual graphics technology at this free one hour event hosted by= =20 > HP, AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebina= r > _______________________________________________ > Parseperl-discuss mailing list > Par...@li... > https://lists.sourceforge.net/lists/listinfo/parseperl-discuss |