Perl keeps a database of external dynamically loaded libraries by their file handles in @DynaLoader::dl_librefs
how do I find out what the library is that DynaLoader
keeps the handle to?
sub f {
my $h = shift;
# something that gives me a name, or caller or something useful?
return $name;
};
map f($_), @DynaLoader::dl_librefs;
What can I do?
DynaLoader::bootstrap doesn't save the name of the file it loads ( $file
). [1]
The handles themselves are system-dependent handles. For example, on Windows, they are HMODULE
values returned by LoadLibraryExA
(dynamically linked) or GetModuleHandle
(statically linked). On that system, you could use GetModuleFileName
.
However, it does associate the path with a sub named bootstrap
in the module's package. You can use the following snippet to find the path of the library of a specific DynaLoader-using module.
use B qw( svref_2object ); my $module_name = 'Foo::Bar'; my $glob = do { no strict qw( refs ); *{$module_name.'::bootstrap'} }; my $code = *$glob{CODE} or die("Module $module_name not loaded or doesn't use DynaLoader\\n"); my $path = svref_2object($code)->FILE;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.