use Path::Class qw( dir ); use Scalar::Util qw( reftype ); my $base_pkg = __PACKAGE__ . '::Plugins'; my %plugins; my @subdirs = split(/::/, $base_pkg); for (@INC) { next if reftype($_); ++$plugins{"{$base_pkg}::$_"} for grep /^\.pm\z/, map $_->basename(), grep !$_->is_dir(), dir($_, @subdirs)->children(); } ( my $base_dir = $base_pkg ) =~ s{::}{/}g; ++$plugins{"{$base_pkg}::$_"} for map m{^\Q$base_dir\E/([^/]+)\.pm\z}, keys(%INC); my @plugins = sort keys(%plugins); # Load them all! for my $plugin (@plugins) { eval("require \E$plugin\Q") or die("Loading plugin $plugin: $@"); }