Class::Prototyped - Fast prototype-based programming in Perl

Ned Konz ned at bike-nomad.com
Thu Aug 2 04:18:49 UTC 2001


Toby Everett and I have come up with a Perl module that gives Perl a 
Self-like object model. If you're interested in using prototype-based 
programming but can't get Self to work, you might consider this.

One of the interesting things about this is that it uses Perl's built-in 
multiple inheritance and reflection support, and so allows mixing class-based 
and prototype-based idioms in a reasonably sensible (we think) manner.

Tell us what you think. It's made Perl programming more interesting for us, 
at least!

Currently, it's a bit of a memory hog (1.3K+ per object, ~3K for about 4 
slots). It executes methods just as fast as native Perl method lookup, though.

When we figure out a way to do it without sacrificing too much performance, 
we're going to come up with a version that uses less memory than this for 
clones (currently each Prototyped object has its own symbol table; we can 
share these for clones and do a copy-on-write as soon as we can come up with 
a way to handle data slots efficiently with this model).

Here's a copy of the announcement I made to the comp.lang.perl.announce 
newsgroup:

Class::Prototyped - Fast prototype-based OO programming in Perl

Class::Prototyped version 0.11 has been released to CPAN.  It is
available from your local CPAN mirror as (for instance):

http://www.cpan.org/modules/by-authors/id/N/NE/NEDKONZ/Class-Prototyped-0.11.tar.gz
or
ftp://ftp.cpan.org/pub/CPAN/authors/id/N/NE/NEDKONZ/Class-Prototyped-0.11.tar.gz

This package provides for efficient and simple prototype-based
programming in Perl. You can provide different subroutines for each
object, and also have objects inherit their behavior and state from
another object.

Method invocation is as fast as in regular Perl. Data inheritance and
accessors are provided using closures. It does not use AUTOLOAD.

If you're familiar with the Self language, this will look quite
familiar.

If you find yourself using objects whose behavior is wholly or partially
determined by closures or CODE references, you should consider trying
this package.

If you're modifying @ISA or symbol tables on the fly, you should
consider using this package.

If you're using Class::SelfMethods, Class::Classless, or Class::Object,
you should _definitely_ consider using this package.

Automatic delegation is also provided, as is a full reflection
interface.

You can do the following:

* Make objects that live in their own classes

* Inherit from objects _or_ classes

* Add or remove methods from objects or classes dynamically

* Modify inheritance dynamically

* Automatically delegate specific methods to a particular object or
class

* Mix-in behavior simply from classes or objects

* Examine the capabilities and inheritance of your objects and/or
classes using a simple, consistent interface (no more inspecting @ISA or
symbol tables)

* Perl code in external files can be mixed in to the behavior of a class
or object (like the way Ruby handles mixed-in modules).

Class::Prototyped was written by Ned Konz and Toby Everett; we welcome
feedback on its design and usage. Toby wrote Class::SelfMethods and is
now using Class::Prototyped instead.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com



More information about the Self-interest mailing list