This file was automatically generated from http://svn.pugscode.org/pugs/misc/old_pugs_perl5_backend/Perl6-MetaModel/docs/S12.5.pod on Thu Jul 12 12:23:24 2007 GMT, revision 16992.
Synopsis 12.5 - The Perl 6 Meta Object Protocol
This is an unofficial amendment to Synopsis 12, which describes the design and implementation of the Perl 6 Meta Object Protocol.
It expands upon the section entitled "Introspection" in Synopsis 12, which only describes the meta-"data" available from the metaclasses. In this document I will describe how that meta-data can be manipulated as well.
NOTE: For a quick overview of the MetaModel itself please see the 10_000_ft-view.pod in this same directory.
A meta object protocol is basically an API for the elements of the meta-level classes
and objects which are exposed to user level code. Basically this describes all the things
you can do with the object returned by $obj.meta.
The following protocol defines the behavior of all classes in the Perl 6 object model. This is not meant to be documentation for one particular class, but for classes in general.
These methods are very basic introspection methods, some of which are described already in Synopsis 12.
name (Str ?$name) returns Str
This is a read-write accessor method which determines the name of the class it is associated
with. Its default value is undef, which is essentially an anonymous class.
NOTE: Changing the name of a class at runtime is possible, however it is likely that doing so could have many unforseen consequences, and so it is generally discouraged.
version (T ?$version) returns T
Also a read-write accessor method, this is the version number of the class it is associated
with. Its default value is 0.0.0.
authority (Str ?$authority) returns Str
This is also a read-write accessor method; it is the certifying authority for the class it is associated with. This will likely be a string in one of the following formats:
cpan:JRANDOM email:jrandom@cpan.org url:http://www.random-inc.com/~jrandom/
identifier returns Str
This is a read-only method which takes the name, version and identifier and concatenates
them into a single string separated by '-' characters. This is the format found in the class
defintions:
class Foo-0.0.5-cpan:BARBAZ { ... }
The following are methods which can be used to determine superclass relationships as well as the MRO (Method Resolution Order) of a given class.
superclasses (Array of Class ?@superclasses) returns Array of Class
This is a read-write accessor for a class's superclass list. Passing a @superclasses list will
overwrite the list, it will not attempt to push or shift elements onto the list.
Changing the superclass list will result in a recalculation of the classes MRO, and possible other "cache clearing" actions as yet to be determined.
is_a (Class $class) returns Bool
isa, however, it requires a Class instance, and not a Str for it's
argument.
MRO returns Array of Class
dispatcher (+$preorder, +$breadth, +$descendant, +$ascendant) returns Dispatcher
The named arguments here are used as a means of determining the order in which the dispatcher will dispense the class precendence list.
Let me first begin this by saying that there are a number of assumptions made in the MetaModel design regarding methods, they are as follows:
method primative, and that it will properly bind and unbind the $?SELF and
$?CLASS values.
multi method primative, and it will do all the same things as method and it will
be possible to store all variants of the multi-method into a single slot in the class.
There will be a submethod primative, and that it will properly perform the following check prior to
executing the underlying body of code:
next METHOD unless $?SELF.class =:= $?CLASS;
The submethod primative will also properly bind and unbind the $?SELF and $?CLASS values.
private method primative which makes the assumption that the value in $?CLASS will be
the same as the class the method is associated with. The result of this is that the private method can
only be called from within that class. It is also important to note that when dispatching on a private
method the value in $?CLASS should be used to find the methods in. This allows for subclasses to be
the invocant, while still retaining the privacy of the method during internal calls.
has_method (Str $label) returns Bool
get_method (Str $label) returns Method
remove_method (Str $label) returns Void
add_method (Str $label, Method $method) returns Void
This method can be used to associate a $method with a class. It's usage is simple enough:
Foo.meta.add_method('bar', method (Foo $self:) { ... });
get_method_list returns Array of Str
http://www.iam.unibe.ch/~scg/Research/Traits/
(Note: Traits are what inspired the Perl 6 concept of Roles)
There is a good amount of documentation about the Objective C Runtime which explains the class and object structures. Here are some relevant links:
I found some interesting Object Model discussions regarding Ruby here:
Stevan Little <stevan@iinteractive.com>