A new object system for Perl

I just released Dot, it's a new object system for Perl, some of its highlight and difference:
  • There's no code for this object system, you don't even have to install the module to use it.
  • An object is a hash, a method is a closure, and a class is a subroutine.
  • True private variable, not by pretending.
  • Multiple inheritance without the diamond problem.
  • Method dispatching takes zero time, in fact it is not needed at all.
  • The built-in mechanism of Perl 5 OO is completely bypassed.
  • If you want a bird you could inherit from a jungle and remove everything else so that it's the only thing left.
  • You don't need a package to change the inheritance of an object, you only need a single statement.
  • Inheritance of a class could be chosen at runtime, the inheritance of the objects of the same class could thus be different.
  • Easy creation of metaclass, metametaclass, etc.
You can see the full documentation on CPAN.

4 Comments

Very interesting. Dot is more of a technique than code. Suggest you change the docs in one way: Use something other than 'class' for the subroutine name in your examples. I spent a few minutes trying to determine how to create different classes before I realized that all I had to do was change the sub name from 'class' to my class name. Using the generic keyword-looking class is confusing. I would say that we are trying to create the class Foo::Bar so that the examples look like

sub Foo::Bar {
....
}
my $obk = Foo::Bar({});

Interesting...and very clean. So how does one for example use a CPAN module class that is typically instantiated as:

my $foo = Foo::Bar->new(...);

Are there issues with memory leaks? Do you have some more robust examples of code that uses this technique other than test cases?

Quite interesting.

An interesting pattern. Not too far removed from what I did with Class::Anonymous other than I made my objects subrefs and both the data and methods were closures for even more data privacy. I love playing with alternative patterns like this. It is fun that Perl gives us that freedom!

Leave a comment

About Yang Bo

user-pic I blog about Perl.