SMOP p6opaque Implementation: Revision 11
The p6opaque Responder Interface is the default responder for all Perl 6 objects.
This is a hard topic in Perl 6, as compositions are mostly unpredictable (unless the class is closed). This way the composition is made with a "composition pile", where every composition operation is put in order, allowing correct method resolution. But the declarations in a class always override any composition declaration. That way, a prototype have:
So the method lookup always:
Private member lookup always:
An object, on the other hand, have
And an object that can autovivifies have:
Putting this all together, we get to the following structure that every object, defined or not (in which case it is a prototype), have:
The "direct prototype" and the "composition pile" are mutually exclusive members of the object metadata. When an object have simply an "is" in its composition pile, it can be optimized to "direct prototype", which means that the return of WHAT will be that prototype, otherwise the return for WHAT is the object itself.
If an object have empty storage, it's a protoobject, if it have a WHENCE it can be autovivified. A normal object will have only a "direct prototype", on the other hand, it might also have other information, which makes it a self-contained object that is its own class.
Every object returns a different return to HOW. HOW modifies the object, not its prototype. $foo.^add_method(...) is not the same as $foo.WHAT.^add_method(...)