Skip to content

Commit 7ce8859

Browse files
committed
doc role-autopunning
1 parent 7717f69 commit 7ce8859

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

doc/Language/typesystem.pod6

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,20 @@ C<X::Comp::AdHoc> will be thrown.
524524
CATCH { default { say .^name, ' ', .Str } }
525525
# OUTPUT«X::Comp::AdHoc Method 'overload-this' must be implemented by A because it is required by a role␤»
526526
527+
=head3 Role auto-punning
528+
529+
A role can be used instead of a class to created objects. Since roles can't
530+
exist at runtime, a class of the same name is created that will type check
531+
successful against the role.
532+
533+
role R { method m { say 'oi‽' } };
534+
R.new.^mro.say;
535+
# OUTPUT«((R) (Any) (Mu))␤»
536+
say R.new.^mro[0].HOW.^name;
537+
# OUTPUT«Perl6::Metamodel::ClassHOW␤»
538+
say R.new ~~ R;
539+
# OUTPUT«True␤»
540+
527541
=head3 trait C<does>
528542
529543
The trait C<does> can be applied to roles and classed providing compile time

0 commit comments

Comments
 (0)