File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 16
16
17
17
TODO
18
18
19
+ = head3 X < C < handles > |handles trait> trait
20
+
21
+ Defined as:
22
+
23
+ multi sub trait_mod:<handles>(Attribute:D $target, $thunk)
24
+
25
+ The trait C < handles > applied to an attribute of a class will delegate all calls
26
+ to the provided method name to the method with the same name of the attribute.
27
+ The object referenced by the attribute must be initialized. A type constraint
28
+ for the object that the call is delegated to can be provided.
29
+
30
+ class A { method m(){ 'A::m has been called.' } }
31
+ class B is A { method m(){ 'B::m has been called.' } }
32
+ class C {
33
+ has A $.delegate handles 'm';
34
+ method new($delegate){ self.bless(delegate => $delegate) }
35
+ };
36
+ say C.new(B.new).m(); # OUTPUT « B::m has been called. »
37
+
38
+ Instead of a method name a list of names, a C < Regex > or a C < Whatever > can be
39
+ provided. In the latter case existing methods, both in the class itself and
40
+ it's inheritance chain, will take precedence. If even local C < FALLBACK > s should
41
+ be searched use a C < HyperWhatever > .
42
+
43
+ class A {
44
+ method m1(){}
45
+ method m2(){}
46
+ }
47
+
48
+ class C {
49
+ has $.delegate handles <m1 m2> = A.new()
50
+ }
51
+ C.new.m2;
52
+
53
+ class D {
54
+ has $.delegate handles /m\d/ = A.new()
55
+ }
56
+ D.new.m1;
57
+
19
58
= head2 C < role >
20
59
21
60
TODO
You can’t perform that action at this time.
0 commit comments