Reputation: 1
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?
Upvotes: 1
Views: 84
Reputation: 385496
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;
Upvotes: 1