develooper Front page | perl.perl5.porters | Postings from May 2006

Re: [perl #3306] DESTROY doesn't get called.

Thread Previous | Thread Next
Yuval Kogman
May 1, 2006 11:37
Re: [perl #3306] DESTROY doesn't get called.
Message ID:
On Mon, May 01, 2006 at 19:49:41 +0100, Dave Mitchell wrote:

> If bless just does a copy-on-write, then this breaks:
> $ perl588 -we '$a = sub {}; $b = $a; bless $a; print "not ok\n" if $a != $b'

That's technically copying the reference, but yeah.... Either way

> but that's roughly what a CV is anyway: it's an SV that contains pointers
> to an op tree and a scratchpad.

Oh... I was assuming if it were that way then the optimization would
not be so substantial ;-)

In theory a CV could be a pointer to what a CV is now, and *that*
could contain a copy count, but the extra indirection is probably
going to be slower, overall, than copying that bit.

I still would like proper destructors for code refs - i have a
stupid module up on the CPAN for exactly that reason - it's a
wrapper object that overloads deref-as-code and allows you to
specify a custom destructor. It doesn't work when you have a bit of
code that takes either a code ref or an object, of course.

But ideally if you have a sub that returns a closure, and then some
day stops returning a closure but returns a regular sub with the
same behavior, then the user of that code reference would get
consistent blessing behavior.

Thanks for clarifying,

  Yuval Kogman <>  0xEBD27418

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About