in reply to Re: INIT blocks and runtime code loading
in thread INIT blocks and runtime code loading

One wrinkle on broquaint's kludge is its interaction with an import subroutine.
'use'ing a module normally goes through:
BEGIN
import
INIT
However, adding an import subroutine to the above code produces:
BEGIN
INIT
import
One possible workaround for this would be to move any INIT code to the end of the import subroutine. Yet even this is not a 100% solution as:
use testpkg ();
causes the import subroutine - and hence the moved INIT code - not be be executed.

For the module I'm writing, I have a BEGIN block, an import subroutine, and an INIT block. The INIT block consists of just one function call. Therefore, I warn the user that if they want delayed evaluation of my module, they must do so as follow:

eval { require MyModule; import MyModule qw/.../; MyModule::MyInit(); }

Remember: There's always one more bug.