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.";

In reply to Re: Re: Coding perl a plugin system? by sauoq
in thread Coding perl a plugin system? by skx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.