develooper Front page | perl.perl5.porters | Postings from January 2012

Re: [perl #3306] DESTROY not called on code reference objects

Thread Previous | Thread Next
From:
Zefram
Date:
January 3, 2012 03:56
Subject:
Re: [perl #3306] DESTROY not called on code reference objects
Message ID:
20120103115645.GB9071@lake.fysh.org
Olivier Mengu?? via RT wrote:
>Blessing multiple times the same value multiple time can only lead to
>unexpected behavior

No, it has perfectly well-defined behaviour, and can reasonably be
used deliberately.

>So I think that the proper fix for this issue would be that bless die
>for non-closure subs as it does in the other constants cases (where it
>dies with "Can't bless non-reference value").

I get "Modification of a read-only value attempted" if I try, say,
bless(\1, "Foo").  Note that it's the thing the reference points at,
not the reference itself, that gets blessed, so bless(1, "Foo"), which
is what gets "Can't bless non-reference value", is nonsensical rather
than just not permitted.

It would be vaguely sensible for non-closure subs to be marked readonly
and so be unblessable, but it seems equally sensible for closures too.
It should be possible to bless subs somehow, though, so we can't very well
have all (non-closure) subs readonly to start with.  It's also way too
late to change the default behaviour.  If you want a sub to be readonly
that can be arranged (Internals::SetReadOnly from the CPAN version of
Internals), and you can sensibly have a :ro attribute to express it.

It's not sensible to change the existing behaviour of blessing subs.

-zefram

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About