Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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 } } }


Thanks!

In reply to Mileage with safe by simon.proctor

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2022-08-18 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?