develooper Front page | perl.moose | Postings from February 2009

Cookbook: basic recipe3: 'before' not needed

Thread Next
From:
Otto Hirr
Date:
February 3, 2009 22:53
Subject:
Cookbook: basic recipe3: 'before' not needed
Message ID:
8F48885B0A8B404CBF6E09444B25472C@olabinc.com
Going back over recipe3, I believe that the:

1  before 'right', 'left' =>sub {
2    my( $self, $tree ) = @_;
3    $tree->parent( $self ) if defined $tree;
4  }

is not needed and line 3 is dead code...
Try rewriting with:

3a   if( defined $tree ){
3b     $tree->parent( $self );
3c   }

and place a break point on 3b. It is never called.
That is because you would have to have an explicit param,
like $t1->left( $t2 ). That would result in the following:
  $t2->parent( $t1 )
which seems wrong.

The recipe states: 
  'They will not install the parental relationships that we need.'
but they do, as demonstrated by the test code, there are parent,
left, and right nodes.
It seems to me that the above result, ie: $t2->parent( $t1 )
winds up ripping out the node from the tree.

So where am I flawed in my thinking.

Regards,

..Otto



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About