Any way to "inject" an INIT block into a different module?

Andy Wardley abw at wardley.org
Fri May 30 16:17:45 BST 2008


Abigail wrote:
> Well, if it's acceptable to do the "use Control" from the Amp.pm module
> (as you were doing it initially), wouldn't moving the "use Control" to
> end of the package solve the problem? By the time Control -> import ()
> gets called, all the subs of Amp.pm are defined.

Yes, it would.  Although it might be a bit backwards have a "use" right at
the end of the file.  Furthermore, the real equivalent of my Control module
is also defining some constant subroutines and package vars that really do
need to be done up front so they can be used in the code body.  But I could
just as easily call another method at the end.

     use Control qw( volume sustain );

     # my code
     blah blah $CONTROLS;     # $CONTROL is exported by Control, for e.g.

     __PACKAGE__->generate_controls;

Or I could put the explicit generate_controls() call in an INIT block at the
top.  But then we're back to manually doing what I'm trying to automate from
the Control module.

Cheers
A




More information about the london.pm mailing list