Thread: [Parseperl-discuss] PPI + Storable = ?
Brought to you by:
adamkennedy
From: Johan L. <jo...@Da...> - 2005-07-07 23:09:17
|
I'm trying to cache parsed PPI::Document objects by serializing them with Storable, but I see strange things. The objects before/after look the same, but e.g. a $node->statement doesn't work with the thawed object. Is there any known reason it wouldn't "just work" to freeze/thaw a PPI::Document with it's nodes etc? /J |
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 |
From: Johan L. <jo...@Da...> - 2005-07-08 09:09:23
|
At 10:23 2005-07-08, Adam Kennedy wrote: >Write me a quick 17_storable.t test script (just copy one of the other >smaller test scripts) and attach it to a rt.cpan.org bug report, and I'll >handle the implementation for you. I probably should refactor that bit a >little anyway so it uses the same code as ->clone. Will do. (But I'm not sure I'll get the time until perhaps Sunday if that has any impact you your scheduled release.) Thanks, /J -------- ------ ---- --- -- -- -- - - - - - Johan Lindström Sourcerer @ Boss Casinos johanl AT DarSerMan.com Latest bookmark: "TCP Connection Passing" http://tcpcp.sourceforge.net/ dmoz: /Computers/Programming/Languages/JavaScript/ 12 |
From: Adam K. <ad...@ph...> - 2005-07-08 11:02:20
|
Johan Lindstrom wrote: > At 10:23 2005-07-08, Adam Kennedy wrote: > >> Write me a quick 17_storable.t test script (just copy one of the other >> smaller test scripts) and attach it to a rt.cpan.org bug report, and >> I'll handle the implementation for you. I probably should refactor >> that bit a little anyway so it uses the same code as ->clone. > > > Will do. (But I'm not sure I'll get the time until perhaps Sunday if > that has any impact you your scheduled release.) Depends which country you are in, but it's fairly safe to say Sunday is fine as long as it's fairly early in the day. Saturday would be better, if possible. It's a fairly standalone feature, so it won't get in the way of any of the other work though. Adam K |
From: Johan L. <jo...@Da...> - 2005-07-08 15:50:14
|
At 10:23 2005-07-08, Adam Kennedy wrote: >Write me a quick 17_storable.t test script (just copy one of the other >smaller test scripts) and attach it to a rt.cpan.org bug report, and I'll >handle the implementation for you. I probably should refactor that bit a >little anyway so it uses the same code as ->clone. Done. I'm in a hurry now, so take a brief look at the naming convention, it's not perfect. /J -------- ------ ---- --- -- -- -- - - - - - Johan Lindström Sourcerer @ Boss Casinos johanl AT DarSerMan.com Latest bookmark: "TCP Connection Passing" http://tcpcp.sourceforge.net/ dmoz: /Computers/Programming/Languages/JavaScript/ 12 |
From: Adam K. <ad...@ph...> - 2005-07-08 21:43:59
|
Did a bit of rewriting and added a few more tests, but 17_storable.t now=20 passes. Storable now works for PPI 1.000 (version updated in CVS now). Adam K Johan Lindstrom wrote: > At 10:23 2005-07-08, Adam Kennedy wrote: >=20 >> 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=20 >> that bit a little anyway so it uses the same code as ->clone. >=20 >=20 > Done. I'm in a hurry now, so take a brief look at the naming convention= ,=20 > it's not perfect. >=20 >=20 > /J >=20 > -------- ------ ---- --- -- -- -- - - - - - > Johan Lindstr=F6m Sourcerer @ Boss Casinos johanl AT DarSerMan.com >=20 > Latest bookmark: "TCP Connection Passing" > http://tcpcp.sourceforge.net/ > dmoz: /Computers/Programming/Languages/JavaScript/ 12 |