The use keyword is quite simple in its idea. It just looks up a file, and then issues an import call on that package. It will look in the directories listed the @INC array, which you can modify through the lib pragma. This means that use MyPackage::Package2; will look for MyPackage/Package2.pm. But it will also issue an import call on MyPackage::Package2, MyPackage::Package2->import(), but that will do nothing, because in Package2.pm you have package Package2; (I presume). So there is no MyPackage::Package2 package.
Changing package Package2; to package MyPackage::Package2; will just make the import call work right, but it won't make Package1 find Package2 through use Package2;, since the lookup is done through the file system. This also won't make it possible to move modules around to different "packages", (java-style packages).
So what you really want to do is to keep your packages named whatever you want them to be. The way to make them all use()able is by using the lib pragma. @INC is a global variable, and all packages will share it, so if one package can use Package1;, then all other can too. This means that the problem will solve itself once the first modules is loaded if loaded via use, since that will make sure that MyPackage is in @INC.
Hope I've helped,In reply to Re: "Packaging" Perl modules
by ihb
in thread "Packaging" Perl modules
by Heidegger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |