diotalevi has asked for the wisdom of the Perl Monks concerning the following question:
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.]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ISA but no farther?
by ikegami (Patriarch) on Jul 20, 2006 at 17:57 UTC | |
|
Re: ISA but no farther?
by Tanktalus (Canon) on Jul 20, 2006 at 16:29 UTC | |
by diotalevi (Canon) on Jul 20, 2006 at 16:45 UTC | |
|
Re: ISA but no farther?
by diotalevi (Canon) on Jul 20, 2006 at 16:22 UTC | |
|
Re: ISA but no farther?
by ysth (Canon) on Jul 20, 2006 at 16:29 UTC | |
by diotalevi (Canon) on Jul 20, 2006 at 16:33 UTC | |
by ysth (Canon) on Jul 20, 2006 at 17:00 UTC | |
by diotalevi (Canon) on Jul 20, 2006 at 17:18 UTC | |
by jhourcle (Prior) on Jul 20, 2006 at 18:21 UTC | |
|