On Thu, Dec 15, 2011 at 10:09 AM, shawn wilson <ag4ve...@gmail.com> wrote:
> Strace stat(64) should do you. > On Dec 15, 2011 8:03 AM, "Ken Peng" <short...@gmail.com> wrote: > > > Hello, > > > > Which module could show the order of loading modules? > > For example, > > > > use Foo; > > use Bar; > > > > BEGIN { > > require A; > > } > > > > I want to know in what order Perl loads these modules. > > > > Thanks. > > > > -- > > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > > For additional commands, e-mail: beginners-h...@perl.org > > http://learn.perl.org/ > > > > > > > The order is Foo, Bar, A; Figuring it out without a module is pretty simple if you know that use is actually roughly the same as saying BEGIN { require Foo; Foo->import(); } And you know from reading the documentation (perlmod, I think) that BEGIN blocks are run in FIFO order -- So the first one seen is run fist, then the second, and so on. But, assuming that you have a truly preposterous amount of modules loading from everywhere and can't check manually, you can actually ask Perl to tell you. There's probably a module on CPAN for this, so this is superfluous, but it's a nice enough exercise. There's two options. An @INC hook, or overriding *CORE::GLOBAL::require. Both have horrible caveats, so this is not something you should use in production unless you know very well what you are doing. The latter is pretty simple: BEGIN { *CORE::GLOBAL::require = sub { say "[@_]"; CORE::require(@_) } } And while that will tell you the order alright, it'll break pretty soon if one of your modules rather rightfully also asks for a minimum version number, like: use List::Util v1; The second way is using an @INC hook, which is explained in perldoc -f require. Here's a pretty simple form: BEGIN { unshift @INC, sub { say "@_[0..$#_]"; return } } But the real question here is, why do you need to know this?