Evan Carroll
Evan Carroll

Reputation: 1

How can I find the DynaLoader mapping of module names to opaque pointers?

According to the docs on DynaLoader

dl_unload_file() Dynamically unload $libref, which must be an opaque 'library reference' as returned from dl_load_file. Returns one on success and zero on failure. This function is optional and may not necessarily be provided on all platforms.

So dl_load_file returns those opaque reference. But what if my file wasn't loaded by explicitly calling dl_unload_file how do I then find out those references?

Upvotes: 2

Views: 107

Answers (1)

Evan Carroll
Evan Carroll

Reputation: 1

You can find those references by using the following variables, as documented in the source

@dl_shared_objects  = ();       # shared objects for symbols we have 
@dl_librefs         = ();       # things we have loaded
@dl_modules         = ();       # Modules we have loaded

However, matching them to the name of the library remains an exercise to the user though it seems as if they're index-sensitive into those three arrays. You can do it like this,

my %db;
foreach my $i ( 0 .. $#DynaLoader::dl_librefs ) {
  $db{$DynaLoader::dl_modules[$i]} = {
    dl_shared_objects => $DynaLoader::dl_shared_objects[$i],
    dl_librefs        => $DynaLoader::dl_librefs[$i],
    dl_modules        => $DynaLoader::dl_modules[$i]
  };
}

Upvotes: 2

Related Questions