Skip Menu |

This queue is for tickets about the Tree CPAN distribution.

Report information
The Basics
Id: 61740
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: Tree

People
Owner: RSAVAGE [...] cpan.org
Requestors: RSAVAGE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.01
Fixed in: (no value)



Subject: add_child() behaviour is erratic
Hi Folks For a tree which has never been serialized to disk, or has been cloned, add_child(Tree -> new(...) ) and add_child({at => $i}, Tree -> new(...) ) both work. For a tree written to disk, or read from disk, the first form works, but the second form dies with: Can't call method "LEVEL_ORDER" on unblessed reference at /home/ron/perl5/lib/perl5/Tree/Persist/DB/SelfReferential.pm line 104. The line in question is: my $traversal = $tree->traverse( $tree->LEVEL_ORDER ); When {at => $i} is used, line 150 calls _create() with a hash which is not blessed into the Tree class. I haven't figured out yet why that is, but I have a demo which invariably fails at this point, so I'm looking in to it.
Hi Folks The problem is line 119 of Tree.pm: $self->event( 'add_child', $self, @_ ); If I change this to: $self->event( 'add_child', $self, @nodes ); my code works as expected. But then, the {at => $i} options are not passed in. Are they needed? The other way to fix it is, restore line 119, and patch Tree::Base. In this, add a copy of sub _strip_options from Tree, and patch _add_child_hander and _remove_child_hander, thus: Change: my ($parent, @children) = @_; push @{$self->{_changes}}, { to my ($parent, @children) = @_; my $opt = $self->_strip_options(\@children); push @{$self->{_changes}}, { Presumably {at => $i} does not have to be passed in to the add/remove child handlers, so the first patch is better. Agreed?
Hi This is fixed by using my patches to Tree::Persist V 1.01. Unfortunately, this latter version is not yet on CPAN because of a problem making me (Ron) co-maint of Tree::Persist.