in reply to Is there a better way to do this?
Perhaps the simplest method would be to have your main module define stubs for those methods that you want to parcel off into other submodules.
Something like (Untested. I may have the details wrong, its not something you use every day):
sub addition { ## stub no strict 'refs'; require 'Date::Math::Add'; *addition = \&Data::Math::Add::addition; goto &addition; }
The first time the stub method is called, it dynamically requires the sub module and then fixes up the linkage by replacing its own reference with that of the method from the newly loaded module; before finally transferring control (via the special goto) to the loaded method.
Subsequent calls would go directly to the loaded method.
|
|---|