1
1
= begin pod :kind("Language") :subkind("Language") :category("fundamental")
2
2
3
- = TITLE Meta-object protocol (MOP)
3
+ = TITLE Metaobject protocol (MOP)
4
4
5
5
= SUBTITLE Introspection and the Perl 6 object system
6
6
7
7
X < |MOP >
8
8
X < |Introspection >
9
9
10
- Perl 6 is built on a meta object layer. That means that there are objects
11
- (the I < meta objects > ) that control how various object-oriented constructs
10
+ Perl 6 is built on a metaobject layer. That means that there are objects
11
+ (the I < metaobjects > ) that control how various object-oriented constructs
12
12
(such as classes, roles, methods, attributes or enums) behave.
13
13
14
- The meta object has a practical benefit to the user when a normal object's type
14
+ The metaobject has a practical benefit to the user when a normal object's type
15
15
is needed. For example:
16
16
17
17
= begin code
@@ -23,9 +23,9 @@ sub show-type($arr) {
23
23
show-type $arr; # OUTPUT: «Array»
24
24
= end code
25
25
26
- To get a more in-depth understanding of the meta object for a C < class > , here is
26
+ To get a more in-depth understanding of the metaobject for a C < class > , here is
27
27
an example repeated twice: once as normal declarations in Perl 6, and once
28
- expressed through the L < meta model |/type/Metamodel::ClassHOW> :
28
+ expressed through the L < metamodel |/type/Metamodel::ClassHOW> :
29
29
30
30
class A {
31
31
method x() { say 42 }
@@ -44,18 +44,18 @@ corresponds to:
44
44
(except that the declarative form is executed at compile time, and the latter
45
45
form does not).
46
46
47
- The meta object behind an object can be obtained with C < $obj.HOW > , where HOW
47
+ The metaobject behind an object can be obtained with C < $obj.HOW > , where HOW
48
48
stands for Higher Order Workings (or, I < HOW the *%@$ does this work? > ).
49
49
50
- Here, the calls with C < .^ > are calls to the meta object , so C < A.^compose > is
50
+ Here, the calls with C < .^ > are calls to the metaobject , so C < A.^compose > is
51
51
a shortcut for C < A.HOW.compose(A) > . The invocant is passed in the parameter
52
52
list as well, to make it possible to support prototype-style type systems,
53
- where there is just one meta object (and not one meta object per type, as
53
+ where there is just one metaobject (and not one metaobject per type, as
54
54
standard Perl 6 does it).
55
55
56
56
As the example above demonstrates, all object oriented features are
57
57
available to the user, not just to the compiler. In fact the compiler just
58
- uses such calls to meta objects .
58
+ uses such calls to metaobjects .
59
59
60
60
= head1 Metamethods
61
61
@@ -98,7 +98,7 @@ Returns the metaclass object, as in "Higher Order Workings".
98
98
C < HOW > returns an object of type C < Perl6::Metamodel::ClassHOW > in this case;
99
99
objects of this type are used to build classes. The same operation on the C < & >
100
100
sigil will return C < Perl6::Metamodel::ParametricRoleGroupHOW > . You will be
101
- calling this object whenever you use the C < ^ > syntax to access meta methods . In
101
+ calling this object whenever you use the C < ^ > syntax to access metamethods . In
102
102
fact, the code above is equivalent to C < say (&).HOW.HOW.name(&) > which is much
103
103
more unwieldy. L < Metamodel::ClassHOW|/type/Metamodel::ClassHOW > is part of the Rakudo implementation, so use with caution.
104
104
@@ -125,29 +125,28 @@ The presence of a C<Scalar> object indicates that the object is "itemized".
125
125
say (1, 2, 3).VAR ~~ Scalar; # OUTPUT: «False»
126
126
say $(1, 2, 3).VAR ~~ Scalar; # OUTPUT: «True»
127
127
128
- = head1 Structure of the meta object system
128
+ = head1 Structure of the metaobject system
129
129
130
- B < Note: > this documentation largely reflects the meta object system as
130
+ B < Note: > this documentation largely reflects the metaobject system as
131
131
implemented by the L < Rakudo Perl 6 compiler|https://rakudo.org/ > , since the
132
132
L < design documents|https://design.perl6.org/ > are very light on details.
133
133
134
134
For each type declarator keyword, such as C < class > , C < role > , C < enum > ,
135
- C < module > , C < package > , C < grammar > or C < subset > , there is a separate meta
136
- class in the C < Metamodel:: > namespace. (Rakudo implements them in the
135
+ C < module > , C < package > , C < grammar > or C < subset > , there is a separate metaclass in the C < Metamodel:: > namespace. (Rakudo implements them in the
137
136
C < Perl6::Metamodel:: > namespace, and then maps C < Perl6::Metamodel > to
138
137
C < Metamodel > ).
139
138
140
- Many of the these meta classes share common functionality. For example
139
+ Many of the these metaclasses share common functionality. For example
141
140
roles, grammars and classes can all contain methods and attributes, as well
142
141
as being able to do roles. This shared functionality is implemented in
143
- roles which are composed into the appropriate meta classes . For example
142
+ roles which are composed into the appropriate metaclasses . For example
144
143
L < role Metamodel::RoleContainer|/type/Metamodel::RoleContainer > implements
145
144
the functionality that a type can hold roles and
146
- L < Metamodel::ClassHOW|/type/Metamodel::ClassHOW > , which is the meta class
145
+ L < Metamodel::ClassHOW|/type/Metamodel::ClassHOW > , which is the metaclass
147
146
behind the C < class > keyword, does this role.
148
147
149
- Most meta classes have a C < compose > method that you must call when you're done
150
- creating or modifying a meta object . It creates method caches, validates things
148
+ Most metaclasses have a C < compose > method that you must call when you're done
149
+ creating or modifying a metaobject . It creates method caches, validates things
151
150
and so on, and weird behavior ensues if you forget to call it, so don't :-).
152
151
153
152
= head2 Bootstrapping concerns
@@ -181,37 +180,37 @@ immutable. This is called I<composition>, and for syntactically declared
181
180
types, it happens when the type declaration is fully parsed (so usually when
182
181
the closing curly brace is parsed).
183
182
184
- If you create types through the meta-object system directly, you must call
183
+ If you create types through the metaobject system directly, you must call
185
184
C < .^compose > on them before they become fully functional.
186
185
187
- Most meta classes also use composition time to calculate some properties like
186
+ Most metaclasses also use composition time to calculate some properties like
188
187
the method resolution order, publish a method cache, and other house-keeping
189
188
tasks. Meddling with types after they have been composed is sometimes
190
189
possible, but usually a recipe for disaster. Don't do it.
191
190
192
191
= head2 Power and responsibility
193
192
194
- The meta object protocol offers much power that regular Perl 6 code
193
+ The metaobject protocol offers much power that regular Perl 6 code
195
194
intentionally limits, such as calling private methods on classes that don't
196
195
trust you, peeking into private attributes, and other things that usually
197
196
simply aren't done.
198
197
199
- Regular Perl 6 code has many safety checks in place; not so the meta model . It
198
+ Regular Perl 6 code has many safety checks in place; not so the metamodel . It
200
199
is close to the underlying virtual machine, and violating the contracts with
201
200
the VM can lead to all sorts of strange behaviors that, in normal code, would
202
201
obviously be bugs.
203
202
204
- So be extra careful and thoughtful when writing meta types .
203
+ So be extra careful and thoughtful when writing metatypes .
205
204
206
205
= head2 Power, convenience and pitfalls
207
206
208
- The meta object protocol is designed to be powerful enough to implement the
207
+ The metaobject protocol is designed to be powerful enough to implement the
209
208
Perl 6 object system. This power occasionally comes at the cost of convenience.
210
209
211
210
For example, when you write C < my $x = 42 > and then proceed to call methods on
212
211
C < $x > , most of these methods end up acting on the L < integer|/type/Int > 42, not
213
212
on the L < scalar container|/type/Scalar > in which it is stored. This is a piece
214
- of convenience found in ordinary Perl 6. Many parts of the meta object
213
+ of convenience found in ordinary Perl 6. Many parts of the metaobject
215
214
protocol cannot afford to offer the convenience of automatically ignoring
216
215
scalar containers, because they are used to implement those scalar containers
217
216
as well. So if you write C < my $t = MyType; ... ; $t.^compose > you are
0 commit comments