All pastes #343691 Raw Edit

Someone

public text v1 · immutable
·published 2007-02-07 06:04 UTC
rendered paste body
#Dynamic module loader for listeners
sub load_modules {
    my @modules_to_load = @_;
    my %modules;
    my @module_paths;

    #print Dumper(@modules_to_load);

    #Construct a full path to the .pm file(s)
    #Also populate the hash with data regarding the modules
    foreach my $inc_path (@INC) {
        foreach my $module_name (@modules_to_load) {

            my $path = $module_name;
            $path =~ s/::/\//;
            my $full_path = $inc_path . "/" . $path . "/";
            if ( -e $full_path ) {
                foreach my $module ( glob "$full_path*.pm" ) {
                    require $module;
                    my $full_module_name = $module_name . "::"
                        . ( fileparse( $module, ".pm" ) );
                    push @{ $modules{$module_name} }, ($full_module_name);
                }

            }

        }
    }
    return \%modules;
}