[Zope-Perl] Perl External Methods

Gisle Aas gisle@ActiveState.com
12 Jun 2000 00:04:26 +0200


Chris McDonough <chrism@digicool.com> writes:

> Gisle Aas wrote:
> 
> > Another approach that I like better could be that all perl function
> > and module names are always (automatically) prefixed by something like
> > "ZopeExt::" in order to limit what can be done.  Perl External Method
> > modules would then need to go into the ./Extensions/ZopeExt directory
> > (or anywhere else perl looks for modules).
> 
> It would seem to me that narrowing the use path this way is a good
> thing.
> We want to make sure that only modules that reside in
> $ZOPEHOME/Extensions are searched for and imported.

If we impose the "ZopeExt::" prefix then I don't see why we actually
need to limit the scope of @INC to this single directory.  Not that it
is actually hard to do, but it might be sites that prefer to set up
the PERLLIB environment variable before starting Zope to tell where
they have placed their Perl External Method modules.  I don't see much
risk with that.

I still think it is a good idea to add $ZOPEHOME/Extensions to @INC
before we require any such perl module.

> I suppose some fiddling with the @INC array would do this.  We'd need to
> then unfiddle it when the method
> was actually run.  I see you have something like that in there commented
> out.

Yup!

Or I should implement bindings for localizing perl stuff from python.
I.e. this perl code:

  {
      local(@INC);
      push(@INC, "$ZOPEHOME/Extensions");
      eval "require ZopeExt::$module";
  }

could be:

  inc = perl.get_ref("@INC")
  try:
     perl.local(inc)
     inc.append(ZOPEHOME + "/Extensions")
     perl.eval("ZopeExt::" + module)
  finally:
     perl.restore(inc) # pair with perl.local()

or is there a way to avoid the try:/finally: stuff here?  I would like
to set up something like Lisp's with-open-file.  I imagine something
like this interface for localizing:

  inc = perl.get_ref("@INC")
  perl.local(inc):
     inc.append(ZOPEHOME + "/Extensions")
     perl.eval("ZopeExt::" + module)


--Gisle