[MTOS-dev] Circular reference issue
Hirotaka Ogawa
hirotaka.ogawa at gmail.com
Tue Jan 15 21:32:19 PST 2008
On Jan 16, 2008 5:08 AM, Timothy Appnel <tim at appnel.com> wrote:
> Nice work Hirotaka! Well done.
>
> Just a couple of things I learned from working out the problems I
> created in XML::Elemental:
>
> There are apparently some issues with weaken and how some people
> install Perl. From the Task::Weaken docs:
>
> > One recurring problem in modules that use Scalar::Util's weaken function is that it is not present in the pure-perl variant.
> >
> > While this isn't necesarily always a problem in a straight CPAN-based Perl environment, some operating system distributions only include the pure-Perl versions, don't include the XS version, and so weaken is then "missing" from the platform, despite passing a dependency on Scalar::Util successfully.
> >
> > Most notably this is RedHat Linux at time of writing, but other come and go and do the same thing, hence "recurring problem".
>
> There doesn't seem to be a better alternative to weaken. I'm just
> pointing this out for future reference in supporting MT installations.
> Perhaps this will be helpful to those creating distributions of MTOS
> also.
Not only adding some comments on MT installation, we may prepare a
utility method for 'weaker reference creation (substitution)' in order
to encapsulate how it works, to use Scalar::Util::weaken or not to
use.
> The other is just coding style with the use of weaken. Lines like these:
>
> + $node->[5] = shift;
> + weaken($node->[5]);
>
> ...can be condensed into one:
>
> + weaken($node->[5] = shift);
>
> It makes for less typing and tighter code. I did it in two lines also
> until it was pointed out to me.
Thanks! I've just learned it from you.
> The template object stash is such a new thing that I think the
> potential impact of breaking compatibility should be minimal if
> anything at all. I'm having a hard time thinking of how you would end
> up with the context object after building and not have a reference to
> the template object.
MT::Template::build() creates $ctx to $tmpl reference temporallily, and
MT::Template::context() creates $tmpl to $ctx reference.
After building, that is, finishing build() method, the former
reference will be destroyed, and only the latter reference will
remain. From then on, whenever $tmpl becomes out-of-scope, $tmpl will
be destroyed. And if there're no other objects who refer to $ctx,
$ctx will be also destroyed. Theoretically.
> I'm still suspicious of how many individual MT::Object implementations
> stash references to each other that I have to wonder of circular
> references are being created in there.
>
> <tim/>
>
> --
> Timothy Appnel
> Appnel Solutions
> http://appnel.com/
>
--
Hirotaka Ogawa makes no sense.
http://as-is.net/blog/
More information about the MTOS-dev
mailing list