in reply to prove can't find my module, even though its directory is in $INC[0]
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:The require function will actually look for the Foo/Bar.pm file in the directories specified in the @INC array.require Foo::Bar; # a splendid bareword
But if you try this: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:my $class = 'Foo::Bar'; require $class; # $class is not a bareword #or require "Foo::Bar"; # not a bareword because of +the ""eval "require $class";
|
|---|
| 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 | |
|
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 | |
by ikegami (Patriarch) on Dec 15, 2025 at 16:40 UTC |