You want to use the AutoLoader module.
The easiest solution is to use the h2xs facility to create a directory and all the files you'll need. Here we assume you have your own directory, ~/perllib/ , which contains your personal library modules.
% h2xs -Xn Sample % cd Sample % perl Makefile.PL LIB=~/perllib % (edit Sample.pm) % make install
The AutoLoader addresses the same performance issues as the SelfLoader. It also provides stub functions that get replaced by the real ones the first time they're called. But instead of looking for functions all in the same file, hidden below a
This setup sounds complicated. If you were doing it manually, it probably would be. Fortunately,
helps out tremendously here. Besides creating a module directory with templates for your
file and other files you'll need, it also generates a Makefile that uses the AutoSplit module to break your module's functions into little files, one function per file. The
As with the SelfLoader, it's easier to develop and test your module without the AutoLoader. Just comment out the
The same restrictions about the invisibility of file lexicals that apply to modules using the SelfLoader also apply when using the AutoLoader, so using file lexicals to maintain private state doesn't work. If state is becoming that complex and significant issue, consider writing an object module instead of a traditional one.