@@ -402,10 +402,6 @@ L<X::Attribute::Required|/type/X::Attribute::Required>.
402
402
CATCH { default { say .^name => .Str } }
403
403
# OUTPUT « X::Attribute::Required => The attribute '$!attr' is required, but you did not provide a value for it. »
404
404
405
- = head3 trait C < does >
406
-
407
- TODO
408
-
409
405
= head3 trait C < hides >
410
406
411
407
TODO
@@ -442,6 +438,42 @@ C<.^ver> and C<^.auth>.
442
438
443
439
= head2 C < role >
444
440
441
+ Roles are class fragments, which allow the definition of interfaces that are
442
+ shared by classes. The C < role > declarator also introduces a type object that
443
+ can be used for type checks. Roles can be mixed into classes and objects at
444
+ runtime and compile time. The C < role > declarator returns the created type
445
+ object thus allowing the definition of anonymous roles and in-place mixins.
446
+
447
+ role Serialize {
448
+ method to-string { self.Str }
449
+ method to-number { self.Num }
450
+ }
451
+
452
+ class A does Serialize {}
453
+ class B does Serialize {}
454
+
455
+ my Serialize @list;
456
+ @list.push: A.new;
457
+ @list.push: B.new;
458
+
459
+ say @list».to-string;
460
+ # OUTPUT « [A < 57192848 > B < 57192880 > ] »
461
+
462
+ Use C < ... > as the only element of a method body to declare a method to be
463
+ abstract. Any class getting such a method mixed in has to overload it. If the
464
+ method is not overloaded before the end of the compilation unit
465
+ C < X::Comp::AdHoc > will be thrown.
466
+
467
+ EVAL 'role R { method overload-this(){...} }; class A does R {}; ';
468
+ CATCH { default { say .^name, ' ', .Str } }
469
+ # OUTPUT « X::Comp::AdHoc Method 'overload-this' must be implemented by A because it is required by a role »
470
+
471
+ = head3 trait C < does >
472
+
473
+ TODO
474
+
475
+ = head3 trait C < but >
476
+
445
477
TODO
446
478
447
479
= head3 Role Arguments
0 commit comments