[Zope-Perl] perl ref len method.

Chris McDonough chrism@digicool.com
Thu, 25 Jan 2001 16:28:47 -0500


Gisle,

I don't think this matters much, but in the perlmodule docs, you say:

len(p) -- for arrays and hashes this return the natural size.  For all other
things it return 1, because Python does not provide hooks for overriding
boolean tests and we want that stuff to be TRUE.

You can override the truth test in Python via __nonzero__ or __len__.

The follwing table defines the truth state of an object based on the
existence of __len__ and/or __nonzero__ and the value that they return:

len        nonzero          is true?
------------------------------------
T          F                 N
F          T                 Y
T          T                 Y
F          F                 N
<undef>    T                 Y
<undef>    F                 N
<undef>    <undef>           Y
T          <undef>           Y
F          <undef>           N

So if you define a __nonzero__ on the perlref class, you needn't force
__len__ to return true on instances where it doesn't make sense.