Methods can't be subclasses, only classes can be. Assuming that you mean 'inherited' instead, use
Class::CanBeA to figure out what the subclasses of Baz are, then use
exists() and
can() to figure out what methods are being inherited in those subclasses and which are defined.
You need to be careful though - perl supports multiple inheritance, so you may need to figure out your subclasses and then figure out all of their parent classes to find all the other roots of the inheritance tree. And if you do have multiple inheritance, I can't think of any way of telling that this subroutine came from that superclass and that this other subroutine came from that other superclass.
package Foo;
sub foo { 'foo' }
package Bar; # Bar inherits 'foo' from Foo
@ISA = qw(Foo);
sub bar { 'bar' } # Bar defines 'bar'
package main;
use Class::CanBeA;
my @subclasses = @{Class::CanBeA::subclasses('Foo')};
foreach my $class (@subclasses) {
print "$class is a subclass of Foo\n";
foreach my $sub (qw(foo bar)) {
if(!exists(&{$class.'::'.$sub}) && $class->can($sub)) {
print $class.'::'.$sub." is inherited\n";
}
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.