in reply to using passed parent object reference to get at attributes

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

Replies are listed 'Best First'.
Re^2: using passed parent object reference to get at attributes
by previous (Sexton) on Dec 20, 2015 at 10:51 UTC
    >So - you are doing it right ! Yes I just re-ran it and to my amazement I am. WOW I was half watching the Strictly come dancing final so that might have impaired my judgement and I made a few changes right at the end but missed that this had solved my problem...Thanks for the confirmation and extra advice. I'd been struggling with how to organise this for a while in the "big" program so this little test has done the business. Thanks.