[Zope-Perl] Re: Getting wierd problem ...

Alan Young alany@qwest.net
Wed, 27 Jun 2001 18:41:39 -0600


On Wednesday 27 June 2001 14:59, Andy McKay wrote:
> You should be able to pass arguments exactly as the same as python args.
> You can also pull out of the request if necessary, there is no difference
> for var|call|in compared to anything else.

Ok.  Then I'm confused.  This is what I'm trying to do, maybe that'll make 
things easier to explain.

BTW,  I've checked the code for dtml-in and it doesn't seem to do exactly 
what I want here.  If it does, please let me know.  Thanks.

The prototype of what I want to do:

sortObjects(ObjectTypeList, PrecedenceList, AttributeList)

sortObjects returns a sequence of objects (like objectValues) of the 
ObjectsTypeList, sorted by AttributeList with PrecedenceList listed first.

example:

<dtml-in "sortObjects('Folder, File, Image', 'Folder', 'id, size')"> would 
return a sequence of all Folder's, File's and Image's sorted by id and then 
size (well, that doesn't make much sense, but you get the idea) with all 
Folder's listed first (the remaining entries ordered without regard to meta 
type).

Within the in tag I should be able to access the objects properties as I 
would with objectValues (<dtml-var title_or_id> would give me the title or id 
for the returned object).

Because I won't be using any modules, just sort, grep and/or map I should be 
able to use a Script (Perl) object.  I've tried both the old and the new one 
just announced here last week.  Maybe you can point out my fallacy.

Create a Script (Perl) object.

Id: sortObjects
Title:
Arguments: ObjectTypeList, PrecedenceList, AttributeList
Code:

This is where it gets interesting.  If I do

my @objs = split /,\s*/, $ObjectTypeList;
my @prec = split /,\s*/, $PrecedenceList;
my @atts = split /,\s*/, $AttributeList;

my $a;
$a .= "$_:" for @objs, @prec, @atts;

return $a;

I get the expected results (<dtml-var "sortObjects('Folder, File, Image', 
'Folder, test', 'id, size') returns the string 
"Folder:File:Image:Folder:test:id:size:").

But now I need to access objectValues, which I'm told has to be through 
$self.  So I add my @objs = $self->objectValues(\@objs) and I get the 
following PerlError:

Global symbol "$self" requires explicit package name at sortObjects line 8.

Ok.  Fair enough.  Add 'self' to the argument list.  It saves.  When I try to 
run my dtml method however, I get the following PerlError:

Can't locate object method "objectValues" via package "Folder, File,Image" 
(perhaps you forgot to load "Folder, File,Image"?) at sortObjects line 8.

Huh?  I thought $self was always available.  *shrug*  The wording of this 
error message indicates to me that the first fields are being shoved into 
$self (see above re expected results).  Ok, wander around and finally 
discover on #zope that this() can be used to pass in self.  Try it as the 
first parameter.  Now I'm getting '[]' returned from the above code.  Try 
moving self and this() to the end of their respective parm lists.  Nope.  
Same thing.

I'm stumped.  I'm obviously missing something really easy but I can't figure 
out what.  Any ideas?
-- 
A mind is a wonderful thing to waste.