File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,31 @@ C<submethod> declarator:
24
24
}
25
25
}
26
26
27
+ Since submethods are not inherited, an interesting use case is precisely
28
+ methods that are going to be called from the I < standard > submethods such as
29
+ C < BUILD > or C < TWEAK > .
30
+
31
+ = begin code
32
+ class Hero {
33
+ has @.inventory;
34
+ has Str $.name;
35
+ submethod BUILD( :$!name, :@!inventory ) {
36
+ @!inventory = self.clean-inventory( @!inventory );
37
+ }
38
+ submethod clean-inventory( @inventory ) {
39
+ @!inventory.unique.sort
40
+ }
41
+ }
42
+
43
+ my Hero $þor .= new( name => "Þor",
44
+ inventory => ( "Mjollnir", "Megingjörð", "Mjollnir" ) );
45
+ say $þor.inventory;
46
+ # OUTPUT: «[Megingjörð Mjollnir]»
47
+ = end code
48
+
49
+ Invoking these methods make sense only in the specific context of the
50
+ submethod it is invoked from.
51
+
27
52
= head1 Methods
28
53
29
54
= head2 method gist
You can’t perform that action at this time.
0 commit comments