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 <nothingmuch@woobling.org> http://nothingmuch.woobling.org 0xEBD27418Thread Previous | Thread Next