I don't have access to a machine with Perl 5.6 on it just yet, but from
looking at the WeakRef docs in CPAN, I think that the below code is the way
to weaken _parent references on elements, as we've been discussing.  Anyone
want to tell me if this works?  (I.e., not merely runs, but correctly
deletes a tree when you no longer hold a reference to it -- as you could
observe by making a tree, holding a ref to a subnode of it, removing your
ref to the root of the tree, and seeing if that subnode can see its parent
anymore.)


require 5.6;
use strict;
use HTML::Element;
use WeakRef;

# usage: $node->weaken_at_and_under

sub HTML::Element::weaken_at_and_under {
  # I'm written by SMB so I get to break encapsulation
  die unless ref $_[0];

  my $this;
  my @todo = ($_[0]);
  while(@todo) { # simple pre-order traverser
    $this = shift @todo;
    weaken($this->{'_parent'})
     if defined($this->{'_parent'})
      && ! isweak($this->{'_parent'});
    unshift @todo, grep ref($_),
     @{$this->{'_content'} || next};
  }
  return;
}

--
Sean M. Burke [EMAIL PROTECTED] http://www.netadventure.net/~sburke/

Reply via email to