File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -524,6 +524,20 @@ C<X::Comp::AdHoc> will be thrown.
524
524
CATCH { default { say .^name, ' ', .Str } }
525
525
# OUTPUT « X::Comp::AdHoc Method 'overload-this' must be implemented by A because it is required by a role »
526
526
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
+
527
541
= head3 trait C < does >
528
542
529
543
The trait C < does > can be applied to roles and classed providing compile time
You can’t perform that action at this time.
0 commit comments