Perl 6
SMOP OO API: Revision 41

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 API

This is what is implemented by Object

method new($prototype: *@protoobjects, *%initialize --> Object) {...}
method bless($prototype: $candidate?, *@protoobjects, *%initialize --> Object) {...}
method clone($object: --> Object ) {...}
method can($object: $name, $capture? --> List of Method) {...}
method does($object: $prototype --> bool) {...}
method isa($object: $prototype --> bool) {...}
method defined($object: --> bool ) {...}
method CREATE($prototype: :$repr --> Object) {...}
method BUILDALL($object: *@protoobjects, *%initialize) {...}
method DESTROYALL($object: ) {...}
submethod BUILD($object: *@protoobjects, *%initialize) {...}
submethod DESTROY($object: ) {...}

Package API

As submethods are stored in the package as subroutines with invocants, we need to have the API for Package defined here.

method CANDO($package: $name, $capture? --> List of Sub) {...}
method members($package: --> Hash ) {...}


This 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).

method ^CREATE($object: --> Object ) {...}
method ^methods($object: --> List of Method ) {...}
method ^attributes($object: --> List of Attribute ) {...}
method ^isa($object: $superclass --> bool ) {...}
method ^does($object: $otherclass --> bool ) {...}
method ^can($object: $identifier, $capture? --> List of Method) {...}
method ^has($object: $identifier --> Attribute ) {...}


The 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: --> Object ) {...}
method ^!DESTROY($object: ) {...}
method ^!clone($object: --> Object ) {...}
method ^!initialize_instance_storage($object: $package) {...}
method ^!destroy_instance_storage($object: $package) {...}


The 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.

method ^!defined($object: --> bool ) {...}

Skipping lookup on instances

The 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, this is a prototype.

In order to avoid defining Undef, you can only add instance storage to "instance" values. You can't have a "defined" class.

method ^!instance($object: --> bool ) {...}

RW introspection API

Trying to access the private storage of a class (which returns false to "instance") will result in a failure. Trying to add definitions to a defined object will result in a failure.

method ^!whence($object: --> Routine ) is rw {...}
method ^!isa($object: --> Array of Class ) {...}
method ^!role($object: --> Array of Role ) {...}
method ^!private_storage($object: $package --> Hash ) {...}
method ^!class_storage($prototype: --> Hash ) {...}
method ^!methods($prototype: --> Array of Method ) {...}
method ^!attributes($prototype: --> Array of Attribute ) {...}
method ^!package($object: --> Package ) is rw {...}
^!properties($object: --> Hash ) {...}
# these are the helper methods
method ^!can($prototype: $name, $capture? --> List of Method ) {...}
method ^!has($prototype: $name --> Attribute ) {...}

Upload Files

Click "Browse" to find the file you want to upload. When you click "Upload file" your file will be uploaded and added to the list of attachments for this page.

Maximum file size: 50MB

File Name Author Date Uploaded Size

Save Page As

Enter a meaningful and distinctive title for your page.

Page Title:

Tip: You'll be able to find this page later by using the title you choose.

Page Already Exists

There is already a page named XXX. Would you like to:

Save with a different name:

Save the page with the name "XXX"

Append your text to the bottom of the existing page named: "XXX"

Upload Files

Click "Browse" to find the file you want to upload. When you click "Add file" this file will be added to the list of attachments for this page, and uploaded when you save the page.

Add Tags

Enter a tag and click "Add tag". The tag will be saved when you save the page.