|
Perl 6
SMOP OO API: Revision 34
In order to ensure the interoperability among object representations and even between different object systems that uses the same representation. In this context we need to define the HOW and REPR API, this is the SMOP OO API that allows representations to be interchanged, and custom BUILD methods to be written. The interesting aspect is that all this methods must be called in the object itself in SMOP, and that's why they have the "^" and "^!" prefixes, where the first mean a HOW call, and the second means a REPR call. It is important to stress that the REPR API is SMOP specific, whereas the HOW API is supposed to be transversal to Perl 6 implementations. Object APIThis is what is implemented by Object
our Object method new($prototype: *@protoobjects, *%initialize) {...}
our Object method bless($prototype: $candidate?, *@protoobjects, *%initialize) {...}
our Object method clone($object: ) {...}
our List of Method method can($object: $name, $capture?) {...}
our bool method does($object: $prototype) {...}
our bool method isa($object: $prototype) {...}
our bool method defined($object: ) {...}
our Object method CREATE($prototype: :$repr) {...}
method BUILDALL($object: *@protoobjects, *%initialize) {...}
method DESTROYALL($object: ) {...}
submethod BUILD($object: *@protoobjects, *%initialize) {...}
submethod DESTROY($object: ) {...}
HOW APIThis is the instrospection API, that is available as standard Perl 6 and relate to the Object considering all the inheritance and composition. This represent all object capabilities, including the inherited ones, not only the ones implemented by this specific instance (as opposed to the REPR API).
our Object method ^CREATE($object: ) {...}
our List of Method method ^methods($object: ) {...}
our List of Attribute method ^attributes($object: ) {...}
our bool method ^isa($object: $superclass) {...}
our bool method ^does($object: $otherclass) {...}
our List of Method method ^can($object: $identifier, $capture?) {...}
our Attribute method ^has($object: $identifier) {...}
REPR APIThe representation API defines how the runtime can ask different representations. This API is the real enabler on having different representations, even for the same classes. Unlike the HOW API, this only applies to this specific object. The responder interface is supposed to intercept that calls and never call them using standard MRO. None of the information returned by the methods of the REPR API reflects inherited behaviours, it reflects only the definitions made in that object. Basic initialization and destruction API.
method ^!CREATE($prototype: ) {...}
method ^!DESTROY($object: ) {...}
method ^!clone($object: ) {...}
method ^!initialize_instance_storage($prototype: $object) {...}
method ^!destroy_instance_storage($prototype: $object) {...}
Defined/UndefinedThe default "defined" implemented by Object, delegates the call to the representation. By default, an object is defined if there is any instance storage initialized. Which basically means that an object is undefined after CREATE and will become defined after BUILDALL.
our bool method ^!defined($object: ) {...}
Skipping lookup on instancesThe instance method defines if this object is a direct instance of some class. This means that it might have only a single isa, no role and it must not have any other definition. If this value is true, then no lookup is made directly in this object, which means the return for WHAT will be the isa of this object. On the other hand, if this returns false, the lookup will start on this class, and the return for WHAT is this object itself. It's important to realise that it is possible for a defined object to return true to this method as well for an undefined object to return false.
our bool method ^!instance($object: ) {...}
RW introspection API
our Routine method ^!whence($object: ) is rw {...}
our Array of Class method ^!isa($object: ) {...}
our Array or Role method ^!role($object: ) {...}
our Hash of Scalar method ^!private_storage($object: $package) {...}
our Hash of Scalar method ^!class_storage($prototype: ) {...}
our Array of Method method ^!methods($prototype: ) {...}
our Array of Attribute method ^!attributes($prototype: ) {...}
our Package method ^!package($object: ) is rw {...}
our Hash method ^!properties($object: ) {...}
# these are the helper methods
our List of Method method ^!can($prototype: $name, $capture?) {...}
our Attribute method ^!has($prototype: $name) {...}
|