Dear monks,
I wonder how I can get a list of all loaded subclasses of a given base class x from a foreign module.
I thought this must be a FAQ, but I could find nothing
in the FAQs, Conway's book 'Object oriented perl' and the cookbook.
I want this because I want to register all of them at initialization time. Currently I use an ugly hardcoded list.
Since my module should be independent of the foreign module, I want to replace the hardcoded list with a dynamically retrieved one. Then all additions/deletions of subclasses would be tracked automatically.
The debugger has a hash %DB::sub containing all subroutines in scope, so in the debugger I could
probably use something like
require 'perl5db.pl';
my $base_class = 'x';
my @subclass_list = grep { $_->isa($base_class) } keys %DB::sub;
How can I get this list without the debugger module?
Thanks very much, hexcoder
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.