in reply to OO-Perl Question: How Do I get a List of derived Classes for a Base Class?

I never felt the need to do such, but here is how I would do it.

Since every symbol table of packages your current package knows about is in the current package's symbol table, and since subclassing basically consists in including the base class in a packages's @ISA array and overriding some methods, I'd look at the current symbol table for packages it contains and see if the @ISA array of those packages contains the package looked for.

Something like this:

#!/usr/bin/perl -w use strict; package Bar; use base 'IO::Handle'; package Element; sub new { my $type = shift; my $self = {}; bless $self, $type; } package Circle; use vars qw(@ISA); @ISA = qw( Element ); package Square; use vars qw(@ISA); @ISA = qw( Element ); package Line; use vars qw(@ISA); @ISA = qw( Element ); package main; sub list_of_derived_classes { my $class = shift; my @pkg_keys; { no strict 'refs'; @pkg_keys = grep { /::$/ } keys %{__PACKAGE__.'::'}; } my @result; for (@pkg_keys) { no strict 'refs'; if (defined ${$_}{ISA}) { push @result, $_ if grep {/^$class$/} @{${$_}{ISA}}; } } s/::$// for @result; @result; } for my $class (qw(Element IO::Handle)) { print "$class\: ",join(', ', list_of_derived_classes($class)),$/; } __END__ Element: Circle, Line, Square IO::Handle: Bar

Converting the symbol table lookups into a form which passes strict 'refs' is left as an excercise to the reader ;-)