[pm-h] When to use "weaken"?
Todd Rinaldo
toddr at cpanel.net
Fri Jan 24 07:12:08 PST 2014
On Jan 24, 2014, at 8:44 AM, Michael R. Davis <mrdvt92 at yahoo.com> wrote:
>>>
>>> If I'm understanding you, that's the definition of a circular reference.
>>>
>>> parent -> child -> parent
>>
>
> Can't locate object method "cfg" via package "XXX::Profiles::Profile" at /usr/lib/perl5/vendor_perl/5.10.0/XXX/Profiles/Profile.pm line 112.
>
> So, weaken must not work like I think. The child has lost the link to the parent. I guess the child to parent link is more important than the parent to child relationship. Maybe I need to weaken the parent ref. Maybe as Todd suggested I need to re-think the architecture.
>
> For now I'm going to exit after a few loops and restart on cron with Sys::RunAlone or something like that.
>
> Maybe I need to use a DESTROY block and undef($self->{"parent"}) in it. Anyone know the gotchas on DESTROY?
>
weaken =~ “lower the reference count by one"
At a glance from the code I saw, you were weakening too much. The way that works is Perl keeps a count of all the things that point to a piece of information. When it drops to zero, the variable is destroyed. The code I saw had 2 occurrences of weaken. It’s likely you’ll need to carefully craft it so only one side weakens.
More information about the Houston
mailing list