4
4
5
5
= SUBTITLE Introspection and the Perl 6 Object System
6
6
7
- Perl 6 is built on a meta object layer. That means that there are objects (the
8
- I < meta objects > ) that control how various object-oriented constructs (such as
9
- classes, roles, methods, attributes, enums, ...) behave.
7
+ Perl 6 is built on a meta object layer. That means that there are objects
8
+ (the I < meta objects > ) that control how various object-oriented constructs
9
+ (such as classes, roles, methods, attributes, enums, ...) behave.
10
10
11
11
To get a feeling for the meta object for C < class > , here is the same example
12
12
twice: once as normal declarations in Perl 6, and once expressed through the
@@ -29,29 +29,28 @@ corresponds to:
29
29
(except that the declarative form runs at comple time, and the latter form
30
30
does not).
31
31
32
- The meta object behind
33
- an object can be obtained with C < $obj.HOW > , where HOW stands for Higher Order
34
- Workings (or, I < HOW the *%@$ does this work? > ).
32
+ The meta object behind an object can be obtained with C < $obj.HOW > , where HOW
33
+ stands for Higher Order Workings (or, I < HOW the *%@$ does this work? > ).
35
34
36
- Here, the calls with C < .^ > are calls to the meta object, so C < A.^compose > is a
37
- shortcut for C < A.HOW.compose(A) > . The invocant is passed in the
38
- parameter list as well, to make it possible to support prototype-style type
39
- systems, where there is just one meta object (and not one meta object per
40
- type, as standard Perl 6 does it).
35
+ Here, the calls with C < .^ > are calls to the meta object, so C < A.^compose > is
36
+ a shortcut for C < A.HOW.compose(A) > . The invocant is passed in the parameter
37
+ list as well, to make it possible to support prototype-style type systems,
38
+ where there is just one meta object (and not one meta object per type, as
39
+ standard Perl 6 does it).
41
40
42
- As the example above demonstrates, all object oriented features are available
43
- to the user, not just to the compiler. In fact the compiler just uses
44
- such calls to meta objects.
41
+ As the example above demonstrates, all object oriented features are
42
+ available to the user, not just to the compiler. In fact the compiler just
43
+ uses such calls to meta objects.
45
44
46
45
= head1 Metamethods
47
46
48
47
These are introspective macros that resemble method calls.
49
48
50
49
Metamethods are generally named with ALLCAPS, and it is considered good
51
50
style to avoid using your own methods with ALLCAPS names. This will avoid
52
- conflicts with any metamethods that may appear in future versions of
53
- the language. Note that if you really must use a method which has an
54
- ALLCAPS name, use quotes around the method name to safely call it indirectly:
51
+ conflicts with any metamethods that may appear in future versions of the
52
+ language. Note that if you really must use a method which has an ALLCAPS
53
+ name, use quotes around the method name to safely call it indirectly:
55
54
56
55
#| THIS IS A CLASS FOR SHOUTING THINGS
57
56
class MY-CLASSES-ARE-ALL-CAPS {
@@ -79,8 +78,8 @@ The package supporting the object.
79
78
= head2 X < WHERE|syntax,WHERE >
80
79
81
80
The memory address of the object. Note that this is not stable in
82
- implementations with moving/compacting garbage collectors. Use C < WHICH > for a
83
- stable identity indicator.
81
+ implementations with moving/compacting garbage collectors. Use C < WHICH > for
82
+ a stable identity indicator.
84
83
85
84
= head2 X < HOW|syntax,HOW >
86
85
@@ -119,27 +118,26 @@ class in the C<Metamodel::> namespace. (Rakudo implements them in the
119
118
C < Perl6::Metamodel:: > namespace, and then maps C < Perl6::Metamodel > to
120
119
C < Metamodel > ).
121
120
122
- Many of the these meta classes share common functionality. For example roles,
123
- grammars and classes can all contain methods and attributes, as well as being
124
- able to do roles.
125
- This shared functionality is implemented in roles which are composed into the
126
- appropriate meta classes. For example
127
- L < role Metamodel::RoleContainer|/type/Metamodel::RoleContainer > implements the
128
- functionality that a type can hold roles and
121
+ Many of the these meta classes share common functionality. For example
122
+ roles, grammars and classes can all contain methods and attributes, as well
123
+ as being able to do roles. This shared functionality is implemented in
124
+ roles which are composed into the appropriate meta classes. For example
125
+ L < role Metamodel::RoleContainer|/type/Metamodel::RoleContainer > implements
126
+ the functionality that a type can hold roles and
129
127
L < Metamodel::ClassHOW|/type/Metamodel::ClassHOW > , which is the meta class
130
128
behind the C < class > keyword, does this role.
131
129
132
130
= head2 Bootstrapping concerns
133
131
134
- You might wonder how C < Metamodel::ClassHOW > can be a class, when being a class
135
- is defined in terms of C < Metamodel::ClassHOW > , or how the roles responsible
136
- for role handling can be roles. The answer is I < by magic > .
132
+ You might wonder how C < Metamodel::ClassHOW > can be a class, when being a
133
+ class is defined in terms of C < Metamodel::ClassHOW > , or how the roles
134
+ responsible for role handling can be roles. The answer is I < by magic > .
137
135
138
136
Just kidding. Bootstrapping is implementation specific. Rakudo does it by
139
- using the object system of the language in which itself is implemented, which
140
- happens to be (nearly) a subset of Perl 6: NQP, Not Quite Perl. NQP has a
141
- primitive, class-like kind called C < knowhow > , which is used to bootstrap its
142
- own classes and roles implementation. C < knowhow > is built on primitives that
143
- the virtual machine under NQP provides.
137
+ using the object system of the language in which itself is implemented,
138
+ which happens to be (nearly) a subset of Perl 6: NQP, Not Quite Perl. NQP
139
+ has a primitive, class-like kind called C < knowhow > , which is used to
140
+ bootstrap its own classes and roles implementation. C < knowhow > is built on
141
+ primitives that the virtual machine under NQP provides.
144
142
145
143
= end pod
0 commit comments