Skip to content

Commit 9c4688c

Browse files
committed
[Mu] document bless and CREATE
1 parent 9439739 commit 9c4688c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/Mu.pod

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,42 @@ used to initialize attributes with accessors of the same name.
7373
Classes may provide
7474
their own C<new> method to override this default.
7575
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+
76112
=head2 print
77113
78114
multi method print() returns Bool:D

0 commit comments

Comments
 (0)