|Do you know where your variables are?|
Coding perl a plugin system?by skx (Parson)
|on Dec 14, 2002 at 02:56 UTC||Need Help??|
skx has asked for the
wisdom of the Perl Monks concerning the following question:
Once upon a time I wrote a C++ MP3 streaming server, this had a core of code, and a framework for plugins.
These plugins worked pretty simply via 'dlopen', etc.
Now I'm recoding the server in perl, and I'd like to have a simple means of extending the software.
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'??
Right now the best solution I've got is something along these lines: (This loads the code via an eval; with the sideeffect that the three plugin functions are present at ::main:: scope - and can access things)