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

There are two things I might suggest:

In the output you provided you gave perl -c /home/henry/gitr/MAS/lib/MAS/Global.pl as an example to show that perl could find it; however, that command would only check the syntax of the file name you provided (the full path to the module). By running perl -c ./t/8bit.t you have perl check the syntax of the test file (it's perl code too, after all), and if it can see the module it should pass.

prove's -I option adds a library path for prove to include when running. prove's man page includes this comment about @INC:

@INC
prove introduces a separation between "options passed to the perl which runs prove" and "options passed to the perl which runs tests"; this distinction is by design. Thus the perl which is running a test starts with the default @INC. Additional library directories can be added via the "PERL5LIB" environment variable, via -Ifoo in "PERL5OPT" or via the "-Ilib" option to prove.
It looks as if using the -I option might add the given path you need to have the test complete successfully.

Hope that helps.

Replies are listed 'Best First'.
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:56 UTC

    My example showing how Perl could find the module was actually perldoc -l which correctly identified the source as /home/henry/gitr/MAS/lib. So Perl's own module-search routines are working OK.

    I tried the -I option, with the same baffling result:

    /usr/bin/prove -I/home/henry/gitr/MAS/lib ./t/8bit.t ./t/8bit.t .. Can't locate MAS::Global in @INC (@INC entries checked: +/home/henry/gitr/MAS/lib ... etc

    The section in the docs that you point out, that there's a separate set of options passed to "options passed to the perl which runs tests" is interesting; but use of the -I option, as it recommends, shows that that's not the problem either.

    I remain baffled, and stymied ...

      Out of curiosity, what does your 'package' statement in the module look like? Is it something like package MAS::Global; , or package Global;?

      I ask because I did a quick test of some code I was working on recently. My code was under ./lib/My/Particle/Moveable.pm, and my test ran correctly if I used package My::Particle::Moveable; but not if I did package Moveable;. (I remember there was some reason for doing it one way and not the other, but I can't remember it at the moment.)

      Hope that helps.

        That's weird, because using a bareword replaces the :: with a slash, so the error should be
        Can't locate MAS/Global.pm in @INC (you may need to install the MAS::G +lobal module) (@INC contains: ... # ^ # | # slash

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        It's package MAS::Global;
      > My example showing how Perl could find the module was actually perldoc -l which correctly identified the source as /home/henry/gitr/MAS/lib.

      Better don't count on that, AFAIR is perldoc using another mechanism to locate documentation.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

        Rather try this
        $ perl -MMAS::Global -e0

        And compare the error message (if it occurs)

        Can't locate MAS/Global.pm in @INC (you may need to install the MAS::G +lobal module) (@INC entries checked: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/ +5.38.2 ... YADDA YADDA ... /usr/local/lib/site_perl). BEGIN failed--compilation aborted.

        next step would be to dump @INC inside a BEGIN{ } right before the use MAS::Global in order to spot differences to successful imports.

        perl -e'BEGIN {warn join " ",@INC};use MAS::Global'

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery