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.
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:
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.
Suppose Foo::Bar is a module implementing a Dot class, you typically create an instance from it by saying:
If the methods of a Dot class only refer to the object through a weakened reference there will be no circular link internally, and thus no memory leak.
I did wrote some non-trivial stuff using Dot with success, it's on my TODO list to upload them to CPAN, but it may take some time. However I will upload a very simple (60 LOC), but non-superficial and useful one in just a couple of days, to demonstrate Dot more.
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!