[Zope-Perl] Send me your Perl Methods
Gisle Aas
gisle@ActiveState.com
05 Sep 2000 22:52:43 +0200
Michel Pelletier <michel@digicool.com> writes:
> Hi gisle and list folks.
>
> I'm sketching out the chapter that covers scripting for the O'Reilly
> zope book. Having never written in Perl, I'm a bit hobbled in the part
> about Perl Methods. Amos claims to know some but I don't believe him.
>
> Can someone send us any interesting examples? At lest highligting some
> concepts I can grasp and work in.
I'm also looking for interesting examples :-)
Do you have any interesting PythonMethod examples? I can probably
translate it to perl for you.
The zope-method.pod in the zope-perl distribution contains some
examples:
An (uninteresting) Python method like this:
Param: self
for item in self["f1"].objectValues():
print item.id(), ": ", item
print "done"
return printed
might look like this when written in perl:
Param: self
my @res;
for ($self->{f1}->objectValues) {
push(@res, join(": ", $_->id, $_));
}
join("\n", @res, "done");
A DTML method like this (from the Elvis tutorial I think):
<dtml-var standard_html_header>
<h2><dtml-var title></h2>
<dtml-call
expr="photoArchive.manage_addImage(
id='', file=file, title=photo_title)">
<p>Thanks for your photo submission.</p>
<dtml-var standard_html_footer>
can be implemented in perl like this:
Param: self, file, photo_title
my @res;
push(@res, $self->standard_html_header($self));
push(@res, "<h2>", $self->title, "</h2>");
$self->{photoArchive}->manage_addImage(*id => "",
*file => $file,
*title => $photo_title);
push(@res, "<p>Thanks for your photo submission.</p>");
push(@res, $self->standard_html_footer($self));
join("", @res);
Regards,
Gisle