in reply to Can I see "requires"?

As others have already said, %INC.

However, note that it's quite possible to directly manipulate this hash:

use 5.010; # Trick perl into thinking that Moose.pm has # already been required. $INC{'Moose.pm'} = '/tmp/Moose.pm'; # Require it for real. But perl does nothing! require Moose; # Perl thinks Moose is loaded. say "Moose is loaded" if $INC{'Moose.pm'}; # But it isn't really, so we don't know VERSION. say 'Moose version:', Moose->VERSION;

I have in the past had cause to directly manipulate %INC. A module I was using wanted to be passed the name of plugin module to use. It would require that plugin and then use it. However, I wanted to define the plugin inline in my code, a la

{ package My::Plugin; ... } Something::That::Uses::Plugins->load_plugin('My::Plugin');

But this caused Something::That::Uses::Plugins to attempt to require the non-existent file "My/Plugin.pm". So...

{ package My::Plugin; ... $INC{'My/Plugin.pm'} = __FILE__; } Something::That::Uses::Plugins->load_plugin('My::Plugin');

And everybody's happy.

But anyway, my point is that although %INC should give you the information you want, it can't necessarily be trusted 100%.

Replies are listed 'Best First'.
Re^2: Can I see "requires"?
by JavaFan (Canon) on Mar 08, 2012 at 16:21 UTC
    A similar trick can be used to make sure code that uses use warnings works under pre-5.6 as well:
    BEGIN { if ($] < 5.006) { $INC{'warnings.pm'} = __FILE__; no strict 'refs'; *{'warnings::unimport'} = sub {0}; } }
    Of course, no warnings will be enabled when run under pre-5.6, but the code will not croak on a use warnings;