[Zope-Perl] Patch for PerlMethods
Gisle Aas
gisle@ActiveState.com
04 Jan 2001 11:39:36 -0800
This patch (on top of zoperl-1.0.beta3) is needed to get method calls
to Zope objects from PerlMethods to work for newer Zope versions. It
depends on beta 5 of 'pyperl' which you can find here:
ftp://ftp.activestate.com/Zope-Perl/pyperl-1.0.beta5.tar.gz
The Beta 5 also make it possible to pass 'perl ref' objects to python
even for MULTI_PERL builds and also make it possible to bootstrap the
whole symbiosis from perl.
Regards,
Gisle
==== //depot/main/Apps/Bifrost/zoperl/lib/perl/Zope.pm#3 ====
@@ -6,6 +6,20 @@
my %mod_stat;
+# Obtain a reference to the getSecurityManager function
+my $AccessControl = Python::Import("AccessControl");
+my $getSecurityManager = Python::getattr($AccessControl, "getSecurityManager");
+
+# Set up $aq_validate to also be a suitable function
+Python::exec(<<EOT);
+def perl_aq_validate(inst, obj, name, v, validate):
+ #print "Validating", name
+ return validate(inst, obj, name, v)
+EOT
+my $aq_validate = Python::eval("perl_aq_validate");
+Python::exec('del(perl_aq_validate)');
+
+
sub require_ext
{
local(@INC) = ("./Extensions", @INC);
@@ -89,12 +103,21 @@
die "Can't invoke method prefixed with '_'";
}
- my $attr = Python::getattr($self, $method);
- my $validate = eval { Python::getattr($self, "validate") };
- if (defined $validate) {
+ my $attr;
+ my $validate = Python::getattr(Python::funcall($getSecurityManager), "validate");
+ if (Python::hasattr($self, "aq_acquire")) {
+ my $aq_acquire = Python::getattr($self, "aq_acquire");
+ $attr = Python::funcall($aq_acquire,
+ $method,
+ $aq_validate,
+ $validate);
+ }
+ else {
+ $attr = Python::getattr($method);
Python::raise('Unauthorized', $method)
- unless Python::funcall($validate, $self, $self, $method, $attr);
+ unless Python::funcall($validate, $self, $self, $method, $attr);
}
+
if (Python::PyCallable_Check($attr)) {
$attr = Python::funcall($attr, @_);
}