in reply to Re: Coding perl a plugin system?
in thread Coding perl a plugin system?
In this case I wanted to run trusted, external, code in ::main scope
Eh? Well, it seems I misread your question. From the original:
Initially I though I could have a 'Plugins::Foo' package and 'use/require' it at runtime via 'eval' however this has the problem that the package loaded thusly can't access variables in the main scope of the server, because they're defined via 'my $foo = ..'.
Is there a simple solution to this, without using 'our'??
Why look for tricks to give your plugins access to lexicals when you don't have to use lexicals in the first place?
You really should allow interaction between your main program and your plugins via a well-defined API, not by jumping through hoops to get the plugin code evaluated in your main program's file scope. (Note that this has nothing to do with the main package scope as your reference to "::main scope" attempts to imply.) That will eliminate your ability to hide implementation specifics from your plugins. Your plugins will all be one unfortunate identifier choice away from clobbering your main program or another plugin.
You might make such a system work as long as you are the only one writing plugins but that defeats the purpose and, in that case, you might as well just extend the main program directly.
I really suggest you rethink your design. You should consider a design whereby the main program shares data with the plugins only by
-sauoq "My two cents aren't worth a dime.";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Coding perl a plugin system?
by skx (Parson) on Dec 15, 2002 at 23:16 UTC | |
by tachyon (Chancellor) on Dec 16, 2002 at 00:08 UTC | |
by sauoq (Abbot) on Dec 16, 2002 at 05:32 UTC |