Fergal Daly wrote:
> 
> With blead, 5.8.2 and probably all perls that have weak refs
> 
> > perl -MScalar::Util=weaken -e '$a=\"h";weaken($a)'
> Modification of a read-only value attempted at -e line 1
> 
> Any good reason for this? It's not documented and it's a pain.
> 
> If you want to weaken refs of unknown origin (eg in a generic cache module) 
> then you actually have to do
> 
> eval {
>         local $SIG{__DIE__};
>         weaken($ref);
> };
> 
> And also you end up with read only refs that don't get garbage collected when 
> they should [1].

Yes.

> Patch for blead attached to fix this by adding PERL_MAGIC_backref to the list 
> of things that can be done to a readonly value. Also applied to 5.8 and maybe 
> 5.6.

This makes me a bit nervous, but I think it's correct ; in fact I was looking
at it currently.

> I added some tests, everything still passes, is there some other reason not to 
> allow this?

I noticed a Point of Style : you patched the core but added a test in
a CPAN module. This test will obviously fail when backported to CPAN. There
are two solutions -- either put the test in a separate file, or skip it for
$] < 5.009 or $] == 5.009 && ! $ENV{PERL_CORE}.

Graham, any comments on this ?

Reply via email to