In order to avoid problems with syntax validation (such as packages reported missing) and the debugger (such as skipped breakpoints), it is best to organize your project according to the conventions of the core Perl distribution:
-
Keep your own modules in dedicated subtrees of your project. For example, create a subdirectory
lib
as the root of the subtree containing all *.pm files. Note that you can have more than one such subtree. For example, you could also createtest/lib
to store modules that are only imported by test scripts. -
Add the root directories of your subtrees to the @INC path (see the section called “Perl Include Path”). For example, add the entries
lib
andtest/lib
there. -
Map package names to paths in the subtree (and vice versa). For example, store code for the package
Foo::Bar
in filelib/Foo/Bar.pm
and ensure thatlib/Foo/Baz.pm
contains only packageFoo::Baz
. -
Store your Perl scripts anywhere you like in the project. For example, in subdirectory
bin
orcgi-bin
. -
To import from a package,
use
it, rather thanrequire
it. For example,use Foo::Bar;
rather thanrequire '../lib/Foo/Bar.pm';