/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:
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:
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.#!/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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Overriding the built-in require function
by moritz (Cardinal) on Feb 04, 2008 at 19:52 UTC | |
by /dev/urandom (Beadle) on Feb 04, 2008 at 19:59 UTC | |
Re: Overriding the built-in require function (@INC)
by tye (Sage) on Feb 04, 2008 at 21:09 UTC | |
by /dev/urandom (Beadle) on Feb 04, 2008 at 21:51 UTC | |
by blahblahblah (Priest) on Feb 05, 2008 at 02:35 UTC | |
by Tanktalus (Canon) on Feb 06, 2008 at 23:06 UTC | |
by lodin (Hermit) on Feb 06, 2008 at 23:46 UTC | |
| |
by lodin (Hermit) on Feb 06, 2008 at 22:53 UTC |
Back to
Seekers of Perl Wisdom