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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.