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

Cookbook: basic recipe3: 'before' not needed

Thread Next
Otto Hirr
February 3, 2009 22:53
Cookbook: basic recipe3: 'before' not needed
Message ID:
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.



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About