in reply to Re: Who am I? Inheritance question
in thread Who am I? Inheritance question

sub instance_meth { my $self = shift; my $class = Scalar::Util::blessed $self; }

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^3: Who am I? Inheritance question
by diotalevi (Canon) on Mar 16, 2006 at 23:26 UTC

    Does this still work if you want $self to lie to instance_meth about what class it is? Can a mock object still be passed in here? I know ref() is overrideable but it's painful. How does a person handle that with Scalar::Util::blessed?

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      Mock objects respond better to blessed() than ref(). Being an mock object implies that it's blessed in the class that it's mocking.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

        Respond better how? If I've an object blessed into Ye::Olde::Proxy and it provides all the interface of Real::Deal, what can it do to inform blessed() that it should return Real::Deal instead of Ye::Olde::Proxy? Ye::Olde::Proxy would be too accurate since the proxy object wants to appear to everyone except itself to be a Real::Deal object. With ref(), it can install its own function into CORE::ref that knows how to lie properly. Is the idea that it's easier to get a lying blessed() function than it is to override CORE::ref()?

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        Being an mock object implies that it's blessed in the class that it's mocking.

        It does? That's the way that the current mock object CPAN modules tend to do it - but it doesn't have to be. I've done mocking with subclasses, and with completely unrelated classes that duck type to the bit that I happen to be testing.