|Do you know where your variables are?|
Re^2: OO-style modifiers for 'sub' ?by adrianh (Chancellor)
|on Jan 26, 2003 at 23:53 UTC||Need Help??|
As other people have pointed out, checking that you are a specific type is just not-Perl. In fact, its not OO either, because it disables inheritance.
All the tests that have been proposed so far work with inheritance. The inheritance problem is when the subroutine isn't called as a method.
If you had a base class (or interface) it would be part of the class hierarchy. So you would have:
Which will be enough (as long as you call foo as a method) to ensure $self is of the appropriate class. Not verbose at all!
I've argued elsewhere that if you don't call foo as a method you deserve all you get :-)
I'm covering the same ground as in Class::Interface -- isa() Considered Harmful - but surely these sort of relationships are exactly what ISA is all about?
I don't understand what the advantage of avoiding explicit inheritance is? I've yet to see an example that wouldn't (in my opinion) be better handled by ISA relationships or delegation.
Can somebody show me what I'm missing? :-)