File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,42 @@ used to initialize attributes with accessors of the same name.
73
73
Classes may provide
74
74
their own C < new > method to override this default.
75
75
76
+ = head2 bless
77
+
78
+ method bless(Mu $candidate, *%attrinit) returns Mu:D
79
+
80
+ Lower-level object construction method than C < new > .
81
+
82
+ If you pass a C < Whatever > as a candidate, it creates a new object
83
+ of the same type as the invocant, and then uses the named arguments
84
+ to initialize attributes.
85
+
86
+ If you pass something else than a C < Whatever > object as a candidate,
87
+ it simply does the attribute initialization on the C < $candidate > .
88
+
89
+ In both cases, the object with the attributes initialized is returned.
90
+
91
+ You can use this method when writing custom constructors:
92
+
93
+ class Point {
94
+ has $.x;
95
+ has $.y;
96
+ multi method new($x, $y) {
97
+ self.bless(:$x, :$y);
98
+ }
99
+ }
100
+ my $p = Point.new(-1, 1);
101
+
102
+ (Though each time you write a custom constructor, remember that it makes
103
+ subclassing harder).
104
+
105
+ = head2 CREATE
106
+
107
+ method CREATE() returns Mu:D
108
+
109
+ Allocates a new object of the same type as the invocant, without
110
+ initializating any attributes.
111
+
76
112
= head2 print
77
113
78
114
multi method print() returns Bool:D
You can’t perform that action at this time.
0 commit comments