[Zope-Perl] features.

Gisle Aas gisle@ActiveState.com
26 Jan 2001 10:59:12 -0800


"Chris McDonough" <chrism@digicool.com> writes:

> >       For
> > >     example, it'd be nice to be able to "return %hash;" at the
> >
> > It would have to be "return \%hash;" otherwise the hash is expanded
> > into a list of key/value pairs.  When I think of it, a Script(Perl)
> > thingy is called in scalar context, which means that this actually
> > returns a fractional string like "1/8".  Just yet another strange
> > feature of perl.  Mainly useful as a boolean test to tell that the
> > %hash contains elements.
> 
> Is it possible to specify that you want a value from a Perl function
> returned in array context from a Perl Script thingy?  I don't even know that
> this is desirable, but I see that it's possible by setting the __wantarray__
> attr on the perlref object, but passing in __wantarray__=1 as an argument to
> a perl doesn't appear to work (although I have absolutely no idea or
> expectation that it should).

You need to get it inserted into the args when the function is
invoked:
    def __call__(self, *args, **kw):
        ...
        args = ("do",) + args
        return apply(perl.safecall, (root, mask, args))

It might make sense to add a checkbox to the Script edit interface
that select between array/scalar context.  In array context I guess we
will end up returning a tuple.

> Regardless, there's a misleading failure with a "__wantarray__=1" kw
> argument in the arg list:
> 
> Error Type: PerlError
> Error Value: Can't declare scalar assignment in "my" at (eval 13) line 3,
> near ") ="
> 
> for the script:
> 
> my %a = ();
> return %a;
> 
> For the same script without __wantarray__=1 in the arglist, a null value is
> returned, but no err is raised.

You can't assign default values to the arguments of Script(Perl).  I
have not tried to make it work.  Should probably check the argument
list for '=' and give a more sensible error message.


> We could alternately do this via a Python wrapper class for perl ref objects
> in zoperl if we want to commit to keeping the C and Python stuff in sync.
> This is an alternate "right thing".  This would also allow us to assert in
> Python that the object implements a "DontCheckMeForSecurity" interface
> (there is new interfaces stuff in Zope for 2.3), which is probably the
> "real" right solution.  That the security policy currently depends on Python
> typing for waiving security checks on an object is suboptimal in this case,
> and declaring such an interface would allow us to partly move away from
> depending on Python typing in an orderly fashion.
> 
> > getitem() like overloading is simply not provided for
> > "Script(Perl,restricted)".  The only thing you can do with python
> > objects here are getattr.
> 
> Bummer.  So basically if you want to do a getitem on a Python object in a
> restricted Perl Script, you're currently out of luck because we can't expose
> Python::getitem due to security constraints, right?

We can expose a careful_getitem() function as Python::getitem.  Can
you tell me how we are to invoke the SecurityManager in this case?

> > The $self->Foo works because we provide a Python::Object::AUTOLOAD
> > method that catch these calls and transforms them into a
> > Python::getattr() call (with automatic Python::apply()) if the fetched
> > attribute happens to be callable).
> 
> Just curious, why is the apply automatic?  Is autocall a Perl idiom?

Because perl does not really have a getattr thing.  In perl there is
no difference between:

   $o->foo;
   $o->foo();

Both is a argumentless call to a method called 'foo'.  DTML also seems
to have this autocall behaviour.