http://qs321.pair.com?node_id=666068

/dev/urandom has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I want to figure out when certain modules are being loaded, and for this reason, I want to override require. So far I've almost managed to achieve what I wanted. I've overridden require, and it is called. The problem is, that it's not called with the module actually required by the user. For instance, if I want to require Net::Ping, I will receive all of its requirements, but I will not receive it. Here is my test script, which illustrates the issue:
#!/usr/bin/perl use strict; *CORE::GLOBAL::require = sub { CORE::require($_[0]); print $_[0], "\n" if $_[0] eq 'Net/Ping.pm'; }; require Net::Ping; my $p = Net::Ping->new;
What am I missing here? Also, if there's a better way of figuring out when modules are loaded (without having to modify the modules themselves), it would be a better solution.