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

I've done no real testing (my food is ready), but is this the effect you are looking for?

#! perl -slw use strict; use 5.010; sub FOO () { 'foo' } BEGIN { undef $::{FOO} } say defined &FOO ? 'subroutine defined' : 'subroutine undef'; say eval 'FOO if $false; 1' ? 'FOO allowed' : 'FOO not allowed'; __END__ C:\test>660264.p10 subroutine undef FOO not allowed

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Removing CODE slot in typeglob / Reversing "use subs ...;"
by lodin (Hermit) on Jan 03, 2008 at 18:21 UTC

    Beware of the $false in there. Your eval fails because you turned on stricture, but even with my $false; it fails, so that's good. Unfortunately it works too well.

    undef $::{FOO} is the same as undef *FOO and that undefined the whole typeglob.

    our $FOO = 'foo'; undef $::{FOO}; print defined $FOO ? 'defined' : 'undef'; __END__ undef
    I only want to remove the CODE slot in the typeglob.

    lodin

      Again, I'm only adressing the symptoms rather than thinking things through, but how's this?

      #! perl -slw use strict; use 5.010; our $FOO = 'fred'; sub FOO () { 'foo' } BEGIN { undef $::{FOO}{CODE} } say defined &FOO ? 'subroutine defined' : 'subroutine undef'; say eval 'FOO if $false; 1' ? 'FOO allowed' : 'FOO not allowed'; print $FOO; __END__ C:\test>660264.p10 subroutine defined FOO not allowed fred

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        It's the $false playing tricks again.

        $::{FOO} is the typeglob for FOO in main, and a typeglob can be dereferenced as a hash, and that's exactly what $::{FOO}{CODE} does. It becomes more clear if you add the arrow: $::{FOO}->{CODE}. The reason it works without the arrow is that $::{FOO} is an element of the %:: hash, so it's no different than $foo{bar}{baz}.

        use 5.010; our %FOO = (CODE => 'hash value'); say $::{FOO}{CODE}; __END__ hash value

        lodin