Skip Menu |

This queue is for tickets about the Tree-MultiNode CPAN distribution.

Report information
The Basics
Id: 5435
Status: resolved
Priority: 0/
Queue: Tree-MultiNode

People
Owner: TODDR [...] cpan.org
Requestors: edwardjsabol [...] iname.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.0.10
Fixed in: (no value)



Subject: Patch to add add_child_node() method or make add_child() work with Node objects
I've patched Tree::MultiNode 1.0.10 to add a method I'm currently calling add_child_node(). It works just like add_child() except it takes either a Tree::MultiNode::Node or a Tree::MultiNode object instead. I found this extremely useful when using recursion to populate a tree. It could also be used to subsume any tree into another tree, so this touches on the topic of the other bug item here asking for methods to copy/move trees/nodes. Alternatively, instead of adding a new method (add_child_node), I could extend the capability of the add_child() method by inspecting the first argument to the method. If the first argument is of type Tree::MultiNode or Tree::MultiNode::Node, then act accordingly. If it's any other type, it would perform exactly as the current implementation of the add_child() method. I think I actually prefer the second option (extending add_child), but I thought I'd check with you first. I can provide a patch for either implementation. *Please* contact me. I hope you are interested in incorporating this feature into Tree::MultiNode. I really need this capability. Thanks.
[guest - Tue Feb 24 20:15:30 2004]: Show quoted text
> I've patched Tree::MultiNode 1.0.10 to add a method I'm currently > calling add_child_node(). It works just like add_child() except it > takes either a Tree::MultiNode::Node or a Tree::MultiNode object > instead. I found this extremely useful when using recursion to > populate a tree. It could also be used to subsume any tree into > another tree, so this touches on the topic of the other bug item > here asking for methods to copy/move trees/nodes. > > Alternatively, instead of adding a new method (add_child_node), I > could extend the capability of the add_child() method by inspecting > the first argument to the method. If the first argument is of type > Tree::MultiNode or Tree::MultiNode::Node, then act accordingly. If > it's any other type, it would perform exactly as the current > implementation of the add_child() method. > > I think I actually prefer the second option (extending add_child), but > I thought I'd check with you first. I can provide a patch for > either implementation. *Please* contact me. I hope you are > interested in incorporating this feature into Tree::MultiNode. I > really need this capability. Thanks.
I'm interested in seeing your implementation. Since the module is fairly old, I'm a bit resistant to changing the API, so I think I preferr your initial implementation of add_child_node vs overloading the behavior of add_child. Could you pleaes forward the patch or attach it to this bug report? Thanks, Kyle
From: Ed Sabol <sabol [...] alderaan.gsfc.nasa.gov>
[KRBURTON - Mon Aug 30 13:08:14 2004]: Show quoted text
> I'm interested in seeing your implementation. Since the module is > fairly old, I'm a bit resistant to changing the API, so I think I > preferr your initial implementation of add_child_node vs overloading > the behavior of add_child. Could you pleaes forward the patch or attach > it to this bug report? > > Thanks, > > Kyle
Hey Kyle, Sorry it's taken so long to get back to you, but I was on vacation when your e-mail came in. I've attached my patch that adds a new method "add_child_node". Unfortunately, I don't have a corresponding patch for the pod, but it should be straightforward enough to document. Later, Ed
--- MultiNode.pm Tue May 27 14:12:40 2003 +++ MultiNode.pm.patched Mon Feb 2 21:12:35 2004 @@ -769,6 +769,48 @@ if $Tree::MultiNode::debug; } +sub add_child_node +{ + my $self = shift; + my($child,$pos) = @_; + my $children = $self->{'curr_node'}->children; + print __PACKAGE__, "::add_child_node() children: $children\n" + if $Tree::MultiNode::debug; + my $curr_pos = $self->{'curr_pos'}; + my $curr_node = $self->{'curr_node'}; + if(ref($child) eq 'Tree::MultiNode') { + my $top = $child->{'top'}; + $child->{'top'} = undef; + $child = $top; + } + confess "Invalid child argument.\n" + if(ref($child) ne 'Tree::MultiNode::Node'); + + $child->{'parent'} = $curr_node; + + print __PACKAGE__, "::add_child_node() adding child $child ", + "to: $children\n" if $Tree::MultiNode::debug; + + if(defined $pos) { + print __PACKAGE__, "::add_child_node() adding at $pos $child\n" + if $Tree::MultiNode::debug; + unless($pos <= $#{$children}) { + my $num = $#{$children}; + confess "Position $pos is invalid for child position [$num] $children.\n"; + } + splice( @{$children}, $pos, 1, $child, ${$children}[$pos] ); + } + else { + print __PACKAGE__, "::add_child_node() adding at end $child\n" + if $Tree::MultiNode::debug; + push @{$children}, $child; + } + + print __PACKAGE__, "::add_child_node() children:", + join(',',@{$self->{'curr_node'}->children}), "\n" + if $Tree::MultiNode::debug; +} + =head2 Tree::MultiNode::Handle::depth Gets the depth for the current node.
From: toddr [...] null.net
I'll be releasing 1.0.11 shortly with option 1. Please let me know if you'd like to review changes.
From: sabol [...] alderaan.gsfc.nasa.gov
On Fri Feb 19 02:01:08 2010, toddr@null.net wrote: Show quoted text
> I'll be releasing 1.0.11 shortly with option 1. Please let me know if > you'd like to review changes.
Talk about a blast from the past! I look forward to the new release.
RT-Send-CC: sabol [...] alderaan.gsfc.nasa.gov
1.0.11 Has been released with the patch applied. In the interests of expediency, I decided not to wait for proper documentation and/or tests. Since this is a new feature and fairly atomic, it shouldn't affect anything else. Thank you for your contribution!