Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Keeping relationally child objects alive with Moo

by choroba (Cardinal)
on Sep 21, 2017 at 12:50 UTC ( [id://1199830]=note: print w/replies, xml ) Need Help??


in reply to Keeping relationally child objects alive with Moo

What you describe is called "composition", and it's often accompanied by "delegation" where the outer object delegates some of its method to the inner one. It's a common pattern and it should work flawlessly in Moo.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Keeping relationally child objects alive with Moo
by anonymized user 468275 (Curate) on Sep 21, 2017 at 14:07 UTC
    That's reassuring, but what about the way I am doing it:
    $self->attribute->{'key'} = $childObject;
    Is this the right way to assign one of many relationally child objects to the relational parent object? Having had some problems I worked around explicitly, I am worried that the reference to the inner object in the above construction is too remote to persist indefinitely just because the parent object persists indefinitely.

    One world, one people

      So, what does ->attribute return?

      If it returns a hashref that is kept alive by $self, you should be fine.

      If it returns something else, you might have a problem.

      But we cannot tell without seeing some representative example.

        The hash keys persist, but sometimes the values (objects) get destroyed/go undef even though obviously $self and all its immediate attributes are still alive and well.

        One world, one people

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1199830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found