Thilosophy has asked for the wisdom of the Perl Monks concerning the following question:
I have a question about the import/export mechanism.
I would like to write an "import" that dynamically creates subroutines and installs them into the calling module. The content of the subroutine can be derived from just the subroutine name.
For example:
package CallingModule; use MyProcedures qw( Wow ); Wow();
The subroutine Wow, for example
would have been created by MyProcedures::import .sub CallingModule::Wow{ print "Wow"; }
I figure I cannot use the standard Exporter for this, so how do I write my own "import" ? Just eval() a string that produces the subroutine? Or make a closure and assign it to the caller's symbol table? Or somehow else?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using import to generate subroutines
by revdiablo (Prior) on Nov 24, 2004 at 01:42 UTC | |
by Thilosophy (Curate) on Nov 24, 2004 at 02:42 UTC | |
by fergal (Chaplain) on Nov 24, 2004 at 09:41 UTC | |
by revdiablo (Prior) on Nov 24, 2004 at 17:23 UTC | |
by fergal (Chaplain) on Nov 24, 2004 at 23:29 UTC | |
| |
|
Re: Using import to generate subroutines
by tachyon (Chancellor) on Nov 24, 2004 at 01:59 UTC | |
by Thilosophy (Curate) on Nov 24, 2004 at 02:34 UTC | |
by tachyon (Chancellor) on Nov 24, 2004 at 03:13 UTC | |
by Thilosophy (Curate) on Nov 24, 2004 at 05:26 UTC | |
by BUU (Prior) on Nov 24, 2004 at 06:37 UTC | |
|
Re: Using import to generate subroutines
by rrwo (Friar) on Nov 24, 2004 at 11:23 UTC |