[Zope-Perl] pyperl 1.0
Gisle Aas
gisle@ActiveState.com
01 Mar 2001 17:54:16 -0800
I decided to declare pyperl non-beta today. You will now find version
1.0 at:
ftp://ftp.activestate.com/Zope-Perl/pyperl-1.0.tar.gz
The zoperl stuff is still beta for a while. We hope to be able to
provide PPMs in a few days so that people can install this without
having to compile it themselves (assuming they use ActivePerl and
ActivePython).
There are no changes to the core of pyperl since the beta8 release.
The only thing that has changed is that I have added two modules to
make it easier to use Perl modules from Python.
The 'dbi2.py' module provide an interface to the Perl DBI that
conforms to Python's own DB API v2. The old 'dbi.py' module continue
to provide the raw DBI interface.
The 'perlmod' module provide a way to access CPAN modules with a
minimum of fuss. It instantly makes Perl OO modules look like plain
Python classes. You only need to prefix the class names with "Perl."
and then use "." where a Perl program would have used "::".
Example:
from perlmod import Perl
ua = Perl.LWP.UserAgent()
res = ua.request(Perl.HTTP.Request("GET", "http://www.python.org"))
if res.is_success():
print res.content()
else:
print res.status_line()
Another (interactive) example:
$ python
Python 1.5.2 (#2, Sep 29 2000, 15:50:24) [GCC egcs-2.91.66 19990314/Linux (egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from perlmod import Perl
>>> q = Perl.Finance.Quote()
>>> q.currency("USD", "EUR")
1.075269
There is also a way to import functions directly from traditional
functional style modules. The syntax here is a bit different:
from perlmod import PerlModule
print PerlModule("MIME::Base64").encode("foo")
Explicit manual import:
from perlmod import PerlModule
encode_base64 = PerlModule("MIME::Base64").encode
print encode_base64("foo")
Import all functions that are exported by default (@EXPORT):
from perlmod import PerlModule
PerlModule("MIME::Base64").__import__("*", locals())
print encode_base64("foo")
Using this kind of interface in plain Zope Python Products or
ExternalMethods might in fact be the best way to build Zope
applications on top of what CPAN has to offer. You don't really have
to use the zoperl products, unless you are a hard-core Perl guy that
still want to use Zope and can't be bothered to learn some Python.
Regards,
Gisle