Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm writing a content delivery system based on the Template Toolkit but with additional functionality added for configuration etc.

One feature that I am working on is to allow plugins to modify the program data as I move from one stage of the application to the next. This is in its early stages and I intend to make this as safe as possible by controlling program access as much as possible.

Currently, I am using 'require' and then 'import' to dynamically load my module and then run three predefined object methods. This is done within an eval block but I feel a little uncomfortable about that (as you can imagine :P). <bt>
Using 'safe' seems to be the answer to my problems as I can expose a single API object to the plugin compartment and control access (unless someone has a better idea?) but not having used it before I was wanting some advice.

Heres the current code where I'm using 'eval':
# -------------------------------------------------------- # Build the environment var. for the plugins # -------------------------------------------------------- my $environment = { 'parser_conf' => $conf, 'vars_conf' => $vars }; # Stage, environment hash, config object runPlugin('2',$environment,$plugin_config);
# --------------------------------------------------------- # runPlugin # ~~~~~~~~~ # Runs a plugin at a given stage of the content engine # phase. Expects the stage, # the environment and the plugin configuration as # parameters. # --------------------------------------------------------- sub runPlugin { my $setting = shift; my $environment = shift; my $plugin_config = shift; return unless defined $setting; return unless defined $environment; return unless defined $plugin_config; if(defined($plugin_config->setting($setting))) { # We have a winner my $module = $plugin_config->setting($setting); $module =~ s/\.(pm|PM)$//; eval{ # Import - create object - run code my $mainmodule = "Plugins/Core/" .$module . ".pm"; require $mainmodule; import $mainmodule; my $obj = $module->new(); $obj->run( $environment ); $obj->closedown(); }; if($@) { # Log this or something } } }


In reply to Mileage with safe by simon.proctor

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2019-12-12 12:04 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found