Tracy Reed wrote:
> ..
> 6. It contains stuff like:
>
> # foreign_call(module, function, [arg]*)
> # Call a function in another module
> sub foreign_call
> {
> local $pkg = $_[0] ? $_[0] : "global";
> $pkg =~ s/[^A-Za-z0-9]/_/g;
> local @args = @_[2 .. @_-1];
> $main::foreign_args = [EMAIL PROTECTED];
> local @rv = eval <<EOF;
> package $pkg;
> &$_[1]([EMAIL PROTECTED]::foreign_args});
> EOF
> if ($@) { &error("$_[0]::$_[1] failed : $@"); }
> return wantarray ? @rv : $rv[0];
> }
>
> Disregarding style/religious issues (braces, indents/lackthereof, etc)
> what is this code supposed to be doing?..
The function is intended to be called as follows:
$rv = foreign_call("f_module", "f_function", args);
or
@rv = foreign_call("f_module", "f_function", args);
depending on the return type of the function (f_function) being called.
The f_module arg may be "" (or 0 or anything that evals to false but not
missing), in which case (if "", say) a default module named "global" is
substituted.
The f_function arg must not be missing and must be a public function in
the given module. This parm is used in an eval without considering
security implications!
The code sort-of tests for bad calling interface, although it's not
clear to me that it prevents abends. Especially if f_module and/or
f_function are missing.
The use of 'local' creates (and overrides) module globals if they do not
already exist. I question whether that was intended.
A reference to @args (may be an empty array, if none were passed) is
stored into a system global at $main::foreign_args, (possibly) for ease
of constructing the eval, or maybe also for debugging -- or perhaps it
was just the first thing that seemed to work. I suppose one might worry
about race condition bugs from the use of this global.
The routine catches any eval exception and calls an error handler error
(that must exist in the current package). It's unknown whether that
error function returns or not. But if it does return, then the routine
under examination may produce unexpected return values (unless maybe the
module global @rv is adjusted in the error routine).
> ..As far as perl goes is this
> decent?..
It seems a bit indecent to me.
Regards,
..jim
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg