Your posted code runs fine for me, and prints "3" as the parent's test attribute value.
Output:
going in
in new for cChild and just calling sub_passed_to_child
yes in passed_sub
$oParent_ref is cParent=HASH(0xf18038)
$oParent_ref->{test_att} is 3
So - you are doing it right !
If you wanted to pass the CHILD, instead of the parent at:
##OLD $self->{sub_passed_to_child}( $self->{parent_obj_ref} );
$self->{sub_passed_to_child}->( $self ); ##New, explicitly d
+e-ref the sub
Then passed_sub would look like:
sub passed_sub {
print "yes in passed_sub\n";
my ($child) = @_; # I don't like using shift here..
print $child->{parent_obj_ref}{test_att}; # 3
Of course, it would be "better", to use a "getter", so typos would be checked at compile time.
</c>
"I can cast out either one of your demons, but not both of them." -- the XORcist
|