All pastes #345023 Raw Edit

Stuff

public text v1 · immutable
·published 2007-02-08 05:20 UTC
rendered paste body

#Dynamic module loader for Packet:: modules
sub load_modules {
    my @modules_to_load = @_;
    my @modules;
    my @module_paths;

    my @already_done;


    #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 $module_name (@modules_to_load) {
        push @already_done, ($module_name);
        foreach my $inc_path (@INC) {

            my $path    = $module_name;
            my @counter = split /::/, $path;
            my $count   = scalar @counter;

            $path =~ s/::/\//g;

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

            }

        }
    }
    push @modules, @already_done;
    return \@modules;
}