Skip to content

Commit 042b055

Browse files
committed
Adds documentation on how to build classes
Using the metamodel. Closes #1641
1 parent 6d250e5 commit 042b055

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

doc/Type/Metamodel/ClassHOW.pod6

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ It is potentially faster than C<.^can> but does not provide a full list of all c
101101
102102
=head2 method compose
103103
104-
method compose(Metamodel::ClassHOW:D: $obj)
104+
method compose(Metamodel::ClassHOW:D: $obj)
105105
106106
A call to C<compose> brings the meta object and thus the class it represents
107107
into a fully functional state, so if you construct or modify a class, you must
@@ -111,4 +111,21 @@ It updates the method cache, checks that all methods that are required by
111111
roles are implemented, does the actual role composition work, and sets up
112112
the class to work well with language interoperability.
113113
114+
=head2 method new_type
115+
116+
method (:$name, :$repr = 'P6opaque', :$ver, :$auth)
117+
118+
Creates a new type from the metamodel, which we can proceed to build
119+
120+
my $type = Metamodel::ClassHOW.new_type(name => "NewType",
121+
ver => v0.0.1,
122+
auth => 'github:perl6' );
123+
$type.HOW.add_method($type,"hey", method { say "Hey" });
124+
$type.hey; # OUTPUT: «Hey␤»
125+
$type.HOW.compose($type);
126+
my $instance = $type.new;
127+
$instance.hey; # OUTPUT: «Hey␤»
128+
129+
We add a single method by using L<Higher Order Workings|/language/mop#index-entry-syntax_HOW-HOW> methods, and then we can use that method directly as class method; we can then C<compose> the type, following which we can create already an instance, which will behave in the exact same way.
130+
114131
=end pod

xt/words.pws

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,3 +1375,4 @@ zoffixznet
13751375
zwj
13761376
mmk
13771377
FQN
1378+
NewType

0 commit comments

Comments
 (0)