Dear Monks
In simple terms I'm trying to think of a way to stop required files from being able to access various procedures, and from stomping on my namespace.
Let me explain further.

I'm trying to create a program which has the ability to use perl plugins, I've trawled the monastery and found some posts about the issue, but I couldnt see anything that addresses this particular angle. The main problem is I want the plugins to be as simple, and as transparent to the writer as possible. Currently a directory of plugins is opened and "required". I've just started learning about using oo in perl, and moved the plugin handling to a module, which presented the problem that plugins had to use main::registerplugin() rather than registerplugin(). Ill post some code to show a dirty hack that gets round the problem.

#### test.pl #!/usr/bin/perl -w use strict; use plugins; my $P = new plugins(); $P->loadplugins(); sub registerplugin { $P->registerplugin(@_); } #### end #### plugins.pm package plugins; use wrap; sub new { my $class = shift; my $self = {}; bless($self, $class); return $self; } sub loadplugins { my $self=shift; wrap::requirer('foo.pl'); } sub registerplugin { my $self = shift; my $arg = shift; print $arg; } 1; #### end #### wrap.pm package wrap; sub requirer { require 'foo.pl'; } sub registerplugin { main::registerplugin(@_); } 1; #### end #### foo.pl registerplugin("hi"); #### end

as you can see this is clearly ludicrous, it helps because when the plugin calls a function it will be called in the wrapper, and the only other thing to worry about is "requrer" (i dont mind that). But its daft. There must be a better way?
Perhaps a complete rethink is in order...

janitored by ybiC: Balanced <readmore> tags around long code block


In reply to quarantining required files by lilphil

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.