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 HackTo 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 HackSuppose 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; BEGIN { my $symbols = Devel::Symdump->new( 'main' ); my @new_funcs = map { s/main:://; $_ } grep { not exists $existing{ $_ } } $symbols->functions( ); local $" = "\\n "; warn qq|Imported:$"@new_funcs\\n|; } As of Perl 5.8.7, this prints: $ perl show_fsf_symbols.pl Imported: catfile curdir updir path file_name_is_absolute no_upwards canonpath catdir rootdir $
Hacking the HackDevel::Symdump works on more than just functions. You can find all exported scalars, arrays, hashes, and file and directory handles, as well as all other symbol tables beneath the named one. Beware, though, that all new symbols have a scalar created by default (at least in Perl prior to 5.9.3), so searching for those isn't as useful as you might think. It would be easy to register a list of all exported functions with the using package, to allow more introspection and runtime. You could even write a module that does this and re-exports them to your package. |