in reply to prove can't find my module, even though its directory is in $INC[0]

It seems your test uses require with a string value, e.g.
require 'MAS::Global'; # or my $class = 'MAS::Global'; require $class;

That's not how require works. In fact, the documentation of the command tells you exactly that:

If EXPR is a bareword, "require" assumes a .pm extension and replaces "::" with "/" in the filename for you, to make it easy to load standard modules. This form of loading of modules does not risk altering your namespace.
In other words, if you try this:
require Foo::Bar; # a splendid bareword
The require function will actually look for the Foo/Bar.pm file in the directories specified in the @INC array.
But if you try this:
my $class = 'Foo::Bar'; require $class; # $class is not a bareword #or require "Foo::Bar"; # not a bareword because of +the ""
The require function will look for the Foo::Bar file in the @INC array and will complain about not finding Foo::Bar there. In this case you can do:
eval "require $class";

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: prove can't find my module, even though its directory is in $INC[0]
by ysth (Canon) on Dec 15, 2025 at 04:30 UTC
    I will add that if they are doing that, it seems like they are trying to explicitly test that the module loads ok, but in a non-standard way.

    The old Test::More framework has a use_ok function, but it is a good idea to only use it in a test file that just does that one test, since other tests may be impacted negatively by not having the module loaded at compile time.

    The new Test2 removes use_ok and just recommends a regular use of the module in your test files.
Re^2: prove can't find my module, even though its directory is in $INC[0]
by HenryLaw (Novice) on Dec 15, 2025 at 08:40 UTC
    No, the test file t/8bit.t uses a simple use MAS::Global;. I just checked.

      You said you got this error message:

      Can't locate MAS::Global in @INC [...]

      The error message indicates that Perl is looking for a file named MAS::Global when you want it to look for a file named MAS/Global.pm.

      This happens, like choroba said, when require "MAS::Global"; is used instead of require MAS::Global; or require "MAS/Global.pm";.

      $ perl -e'require "MAS::Global";' # Bad Can't locate MAS::Global in @INC [...] at -e line 1. $ perl -e'require MAS::Global;' # Ok Can't locate MAS/Global.pm in @INC [...] at -e line 1. $ perl -e'require "MAS/Global.pm";' # Ok Can't locate MAS/Global.pm in @INC [...] at -e line 1.

      So check again, because require "MAS::Global"; or equivalent is definitely used somewhere in your code. The full error message will even say in what file and on what line. Add use Carp::Always; if you need a stack trace.

      If you're still unable to find the problem, start by providing the full (unedited) error message.


      In case you need it, the following is a portable method of converting a package name to a path for require:

      # Equivalent to what `if.pm` uses. my $require_path = $pkg_name =~ s{::}{/}gr . ".pm";