Hack #79. Find Imported Functions
Keep an eye on your namespace.
Importing functions is a mixed blessing. Having functions available from another namespace without having to type their full names is convenient. However, the chance for name collisions and confusion increases with the number of imported symbols.
There are multiple ways to tell the original package of a function, but many of them involve lots of deep magic and, in cases of generated functions, may not tell the whole story. If you really want to know what you've imported and when, the shortest and simplest approach is to use
the Devel::Symdump module.
The Hack
To get a list of functions from a package, create a new
Devel::Symdump object and use the functions( ) method on it:
use Devel::Symdump; my $symbols = Devel::Symdump->new( 'main' ); my @functions = $symbols->functions( );
That gives you a list of fully-qualified function names as of the time of the call. Load and import from the other modules you need, and then create and query a new
Devel::Symdump object to get a longer list of functions.
Running the Hack
Suppose you want to know what File::Spec::Functions imports.[14] If you can wedge the code to create and query the first Devel::Symdump object before the use line executes [Hack #70], all you have to do is perform an array intersection to remove duplicate elements.
use Devel::Symdump; my %existing; BEGIN { my $symbols = Devel::Symdump->new( 'main' ); @existing{ $symbols->functions( ) } = ( ); } use File::Spec::Functions; ...