The hard way is to look inside %:: (or %main:: if you prefer) for keys ending in ::. Let's say that the only package that has been loaded is A::B::C. Look inside %main:: and you will see a variety of things, including a key "A::". This tells you that something has been loaded into the package A. Next you should look at @A::ISA to see if A inherits from your class. Then you look inside %A:: and you will find a key "B::", again check @A::B::ISA, finally you look inside %A::B:: and you will find a key "C::" so check @A::B::C::ISA. When you look inside %A::B::C:: you don't find any keys ending in :: so you're done.
Code would look a little like
check_pkg("::");
sub check_pkg
{
my $pkg = shift;
# ::main:: and :: are the same and we don't want an inifinite loop
return if $pkg eq "::main::";
foreach my $sub_pkg (grep /::$/, keys %{$pkg})
{
my $full_pkg = "$pkg$sub_pkg";
print "checking $full_pkg\n";
print "$full_pkg inherits\n" if check_isa($full_pkg);
check_pkg($full_pkg);
}
}
sub check_isa
{
# check @{$pkg."::ISA"} to see if it inherits
}
The easy way is to use a module to help with this, I thought there was one but I can't find it!
Update: as an aumsement, here's a version that doesn't use recursion
my @to_check = ("::");
while (my $pkg = pop @to_check)
{
next if $pkg eq "::main::"; # because ::main:: and :: are the same
foreach my $sub_pkg (grep /::$/, keys %{$pkg})
{
my $full_pkg = "$pkg$sub_pkg";
print "checking $full_pkg\n";
print "$full_pkg inherits\n" if check_isa($full_pkg);
push(@to_check, $full_pkg);
}
}
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.