Index

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


NAME

Synopsis 12.5 - The Perl 6 Meta Object Protocol

SYNOPSIS

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.

What is a Meta Object Protocol?

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 Perl 6 Meta Object Protocol.

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.

Basic Introspection

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 { ... }

Superclasses and MROs

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
This is a predicate function which is used to determine of one Class instance inherits from another. It is similar in function to 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.

Methods, Submethods, etc.

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:

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
This method returns a list of the method labels for a given class.

SEE ALSO

Books

The Art of the Meta Object Protocol
An excellent book, I cannot recommend it highly enough.

Research Papers

A Core Calculus for MetaClasses
http://research.sun.com/projects/plrg/core-calculus.pdf
Any of these papers on Traits

http://www.iam.unibe.ch/~scg/Research/Traits/

(Note: Traits are what inspired the Perl 6 concept of Roles)

Other Perl Modules

Class::Role, Class::Roles & Class::Trait
The first two are early attempts to prototype role behavior, and the last is an implementation of the Trait system based on the paper which originally inspired Roles.
MiniMetaModel.pl
This is found in this directory, and is a very minimal and readable Meta-Model implementation. The current 2.0 implementation of the metamodel is based on this.

Other Languages

Smalltalk
I prefer the Brown book by Adele Goldberg and David Robinson, but any book that talks about the Smalltalk metaclasses is a good reference.
CLOS
The Common Lisp Object System has a very nice metamodel, and there's plenty of reference on it. In particular there is a small implementation of CLOS called TinyCLOS which is very readable (if you know enough Scheme, that is :).
Objective C

There is a good amount of documentation about the Objective C Runtime which explains the class and object structures. Here are some relevant links:

http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html
... add more links
Ruby

I found some interesting Object Model discussions regarding Ruby here:

http://lazaridis.com/case/lang/ruby/

AUTHORS

Stevan Little <stevan@iinteractive.com>