in reply to Hiding Internal Classes ?

What does a call of a method over a blessed reference if you have deleted the symbol of the package in %main::?

Replies are listed 'Best First'.
Re: Re: Hiding Internal Classes ?
by John M. Dlugosz (Monsignor) on Jul 11, 2001 at 01:09 UTC
    I really don't understand what you said. But, I find that methods can still be called when the symbol for the package is deleted. So, does that mean that blessing is symbolic after all? No, because a newly minted object does not work. So I suspect it's a cacheing thing.

    use v5.6.1; #ActiveState build 626 use strict; use warnings; package Foo; sub bar { print "Foo::bar has been called\n"; } sub new { my $s= 0; return bless \$s, "Foo"; } package main; *newFoo= \&Foo::new; my $x1= new Foo::; $x1->bar(); # OK print "before:", join (' ', keys %main::), "\n"; delete $main::{"Foo::"}; print "after:", join (' ', keys %main::), "\n"; $x1->bar(); # still works! my $x2= newFoo(); # works $x2->bar(); # can't find "Foo"

      Yes, methods are cached. Changing @ISA causes the cache to be invalidated except (apparently) for non-inherited methods. undefing or redefining the subroutine rather than the whole package is correctly handled by the caching code. I'm not surprised that the caching code doesn't expect people to undef the whole package. (:

              - tye (but my friends call me "Tye")
        What's interesting is that $x2 doesn't have the cache like $x1 does. If the class is per-class, as I thought, then blessing it doesn't "connect" it to the cache yet.

        (I plead inocent! Undefing the package was not my idea.)