Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://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 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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found