On Thu, Oct 17, 2002 at 10:24:18PM +0100, Roger Burton West said: > I have a system with a lot of classes, all in the same namespace - > Foo::Bar, Foo::Baz, Foo::Qux, etc. I'm expecting users of the program to > add more classes; these may be in the main program or in additional > files. Is there a way in which the program can get a list of > the names of all Foo::* classes that have been defined?
I use : use File::Find::Rule qw/find/; use File::Basename; my @dirs; foreach my $dir ( map { "$_/Foo/" } @INC ) { push @dirs, $dir if ( -e $dir && -d $dir ); } my @files = find( name => "*.pm", in => \@dirs ); my @modules; foreach my $file (@files) { my ($name) = fileparse($file, "\.pm"); push @modules, $file; } my %modules = map { $_ => 1 } @modules; return sort keys %modules; Which effectively allows you to have plugins. That code above is ripped out of Siesta and if you subsitute 'Foo' for Siesta/Plugin then it allows anybody to install a plugin in the namespace Siesta::Plugin:: and have it picked up on the system. As such it does something slightly different to what Shevek suggested. Simon