如何找到模块名称到不透明指针的 DynaLoader 映射?

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

根据 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.

所以dl_load_filereturns那些不透明的引用。但是,如果我的文件不是通过显式调用 dl_unload_file 加载的,我该如何找出这些引用呢?

您可以使用 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

然而,将它们与库的名称进行匹配对用户来说仍然是一个练习,尽管它们似乎 index-sensitive 进入了这三个数组。你可以这样做,

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]
  };
}