Greetings Monks,

Say I have a class: My::Foo::Bar which inherits from My::Foo, calling My::Foo::Bar->can('a_method') will return true whether a_method is defined in My::Foo::Bar or My::Foo - is there a way to differentate between the two? In other words can I find out not only if a class "can" a method, but also that it's not inherited?

A bit of background on why I need this: I have a set of Class::DBI classes all inheriting from a base class and all defined for the same table. In the base class I have an init() which looks at a specific field and reblesses itself to one of the inheriting classes depending on the value. At this point, I want to call the init() on the newly reblessed reference, only if it defines one (obviously bad things happen if it doesn't).

Sure, there are dozens of trivial workarounds, but this is about learning things, right? :)

Thanks,

PS Sorry if something similar has been answered before - for some reason I am having little luck Super Searching for "can"


In reply to inheritance and can by glwtta

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.