I've been adding some code to perl's B modules to get it to respect OO subclassing but I'm finding that I have to occasionally query that something isn't just a subclass.
Given the following structure BINOP is UNOP is OP, I'd always find that BINOP isa OP. Occasionally I need to know that I really do have an OP object or something that would like to pretend it is an OP object.
I assume this is a sign that subclassing was the wrong route for BINOP and UNOP. Or is it? Is there a circumstance under OO where this is expected?
What's a good perl query for this? Since I know all the things that have subclassed OP I could ask for $obj->isa('OP') and not any { $obj->isa($_) } qw( BINOP UNOP ). That's ugly to look at and expensive to ask for. It'd be much easier to just use ref($obj) but that'd be wrong because then I couldn't use a Test::MockObject object which earnestly wanted to pretend to be a OP object.
ref($obj) can't normally be lied to so now I think I want to have a $obj->is('OP') method which could ignore ISA. I just invented the name ->is(CLASS). Does this method exist under a normal name somewhere in OO-speak? I want to at least steal the common name for the inheritance-ignoring-isa query.
[I suppose should mention that I really meant to write B::OP, B::UNOP, and B::BINOP but found all the B:: parts distracting so I removed them.]
In reply to ISA but no farther? by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |