in reply to Re: Removing CODE slot in typeglob / Reversing "use subs ...;"
in thread Removing CODE slot in typeglob / Reversing "use subs ...;"

The only way I see is saving the typeglob, destroying it and re-creating it with all but the CODE slot

Yup, that is correct. That is how we do it in Class::MOP::Package, and when I was writing that bit at the YAPC::NA 2005 hackathon I queried the collective wisdom of the gurus in attendence (larry, audrey and chromatic to name a few) and they all agreed that was the only way. And AFAIK there is no cleaner way to do it in XS either.

-stvn
  • Comment on Re^2: Removing CODE slot in typeglob / Reversing "use subs ...;"

Replies are listed 'Best First'.
Re^3: Removing CODE slot in typeglob / Reversing "use subs ...;"
by shmem (Chancellor) on Jan 03, 2008 at 23:30 UTC
    I wonder, is that a design accident or intended? you can assign to a typeglob slot (assigning a specific ref to that typeglob), but you cannot undef its value, you have to destroy the whole glob. You cannot assign e.g. an 'undefined subref' to a CODE slot, because... no such thing. Something undef is not a CODE ref.

    Did you get told the rationale behind that? Does anybody know? Cloning a typeglob to get rid of one entry in it looks like "useless use of hoops" to me. IMHO there should be a syntax to remove slots, keys, values and all, as delete does with plain hashes.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Did you get told the rationale behind that? Does anybody know?

      No one told me or gave me any rationale. Most just shrugged and said "yeah its kinda messed up like that". You might note the distinct lack of typeglobs in Perl 6, I don't think they are really thought of as having been that great an idea in the end.

      -stvn
      It has to do with the method cache