Hi Monks,

I've been trying to search for a solution to this for days; any help would be appreciated. Basically, I have a series of classes inheriting from each other, for example, class B is a subclass of class A, and class C is a subclass of class B.

There is an A->source() method defined, which may be overridden in class B. Now in a separate method defined in class A, say:

sub readsource { my $Class = shift; ... $Class->source(); }

So in this method I would like to know in which class the call to $Class->source() will find the source() method.

That is, if source() is not overridden in class B, then calling C->readsource() should know that it accesses A->source() when it calls C->source(). But if source() is overridden, then it should know that it uses B->source().

I would use this information in readsource() to create a new method in the class where I've found source(), a bit like what happens in Class::Data::Inheritable (which appears to use closures to remember where the accessor was defined).

Is there a way to do this without manually parsing the @ISA of all the classes involved?


In reply to Detecting which class a method is defined in by yngwi

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.