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";
In reply to Re: prove can't find my module, even though its directory is in $INC[0]
by choroba
in thread prove can't find my module, even though its directory is in $INC[0] (Solved)
by HenryLaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |