Skip Menu |

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

Report information
The Basics
Id: 40407
Status: resolved
Worked: 20 min
Priority: 0/
Queue: Tree-Simple

People
Owner: Nobody in particular
Requestors: david_cryer [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.18



Subject: Widths incorrectly set when using addChildren
Date: Mon, 27 Oct 2008 04:00:52 -0700 (PDT)
To: bug-Tree-Simple [...] rt.cpan.org
From: David Cryer <david_cryer [...] yahoo.com>
Hi there, I've found that addChildren only appears to increment the width of the node that the children are added to rather than correctly adding them up as the code below shows. Clearly I can work round this with suitable use of fixWidth or by adding the children individually. Found on a system running: Tree:Simple version 1.18 Perl, v5.8.8 Linux 2.6.16.21-0.25-smp #1 SMP Tue Sep 19 07:26:15 UTC 2006 x86_64 x86_64 x86_64 GNU/Linux Otherwise this is proving to be a very useful module. Thanks, David #!/usr/bin/perl use Tree::Simple; # make a tree root my $n0 = Tree::Simple->new("0"); my $n00= Tree::Simple->new("0"); my $n01= Tree::Simple->new("0"); my $n02= Tree::Simple->new("0"); my $n03= Tree::Simple->new("0"); $n0->addChild($n00); $n0->addChildren(($n01, $n02, $n03)); print $n0->getWidth(); $n0->fixWidth(); print $n0->getWidth();
From: david_cryer [...] yahoo.com
On Mon Oct 27 07:02:08 2008, david_cryer@yahoo.com wrote: Show quoted text
> Hi there, > > I've found that addChildren only appears to increment the width of the > node that the children are added to rather than correctly adding > them up as the code below shows. Clearly I can work round this with > suitable use of fixWidth or by adding the children individually. > > Found on a system running: > Tree:Simple version 1.18 > Perl, v5.8.8 > Linux 2.6.16.21-0.25-smp #1 SMP Tue Sep 19 07:26:15 UTC 2006 x86_64 > x86_64 x86_64 GNU/Linux > > Otherwise this is proving to be a very useful module. > > Thanks, > > David > > #!/usr/bin/perl > use Tree::Simple; > > # make a tree root > my $n0 = Tree::Simple->new("0"); > my $n00= Tree::Simple->new("0"); > my $n01= Tree::Simple->new("0"); > my $n02= Tree::Simple->new("0"); > my $n03= Tree::Simple->new("0"); > > $n0->addChild($n00); > $n0->addChildren(($n01, $n02, $n03)); > print $n0->getWidth(); > > $n0->fixWidth(); > print $n0->getWidth();
I've had a chance to look at this a bit further and it seems to me that the code in _setWidth is causing this issue I think in the way that it is trying to cope with a leaf node having children added. An alternative approach that I think solves the problems is given by the diffs below (apologies if I've got the files the wrong way round - I don't do too much of this!): 109,112d108 < if (ref($child_width)) { < return if ($self->{_width} > $self->getChildCount()); < $child_width = $child_width->getWidth(); < } 160a157 Show quoted text
> my $addedwidth = 0;
166c163 < $self->_setWidth($tree); --- Show quoted text
> $addedwidth += getWidth($tree);
168a166 Show quoted text
> $self->_setWidth($addedwidth-($self->isLeaf()?1:0));
Hope this helps, David
Hi David I (Ron) have taken over maintenance of Tree::Simple. I know it's been a long time since you logged your report, but... I've adopted your patch and sample code. See V 1.19. $many $ thanx; Ron Savage