@@ -418,9 +418,9 @@ using C<self>, not the shortcut.
418
418
Note that if the relevant methods C < bless > , C < CREATE > of L < Mu >
419
419
are not overloaded, C < self > will point to the type object in those methods.
420
420
421
- On the other hand, C < BUILDALL > and the submethods C < BUILD > and C < TWEAK > are
422
- called on instances, in different stages of initialization. In the latter two
423
- submethods, submethods of the same name from subclasses have not yet run, so
421
+ On the other hand, the submethods C < BUILD > and C < TWEAK > are
422
+ called on instances, in different stages of initialization. Submethods of the
423
+ same name from subclasses have not yet run, so
424
424
you should not rely on potentially virtual method calls inside these methods.
425
425
426
426
= head2 Private methods
@@ -524,7 +524,7 @@ declared type:
524
524
= end code
525
525
526
526
X < |new (method) >
527
- = head2 X < Object construction|BUILDALL (method) >
527
+ = head2 Object construction
528
528
529
529
Objects are generally created through method calls, either on the type
530
530
object or on another object of the same type.
@@ -544,8 +544,8 @@ L<arguments|/language/functions#Arguments> and uses them to initialize public at
544
544
# OUTPUT: «y: 2»
545
545
546
546
C < Mu.new > calls method L < bless > on its invocant, passing all the named
547
- L < arguments|/language/functions#Arguments > . C < bless > creates the new object and then calls method C < BUILDALL >
548
- on it. C < BUILDALL > walks all subclasses in reverse method resolution order
547
+ L < arguments|/language/functions#Arguments > . C < bless > creates the new object,
548
+ and then walks all subclasses in reverse method resolution order
549
549
(i.e. from L < Mu > to most derived classes) and in each class checks for the
550
550
existence of a method named C < BUILD > . If the method exists, the method is
551
551
called with all the named arguments from the C < new > method. If not, the public
@@ -558,10 +558,11 @@ After the C<BUILD> methods have been called, methods named C<TWEAK> are
558
558
called, if they exist, again with all the named arguments that were passed
559
559
to C < new > . See an example of its use below.
560
560
561
- Due to the default behavior of C < BUILDALL > and C < BUILD >
562
- submethods, named arguments to the constructor C < new > derived from C < Mu > can
561
+ Due to the default behavior of C < BUILD > annd C < TWEAK > submethods, named
562
+ arguments to the constructor C < new > derived from C < Mu > can
563
563
correspond directly to public attributes of any of the classes in the method
564
- resolution order, or to any named parameter of any C < BUILD > submethod.
564
+ resolution order, or to any named parameter of any C < BUILD > or C < TWEAK >
565
+ submethod.
565
566
566
567
This object construction scheme has several implications for customized
567
568
constructors. First, custom C < BUILD > methods should always be submethods,
@@ -621,24 +622,6 @@ merely a common convention, one that is followed quite thoroughly in L<most Perl
621
622
classes|/routine/new > . You can call C < bless > from any method at all, or use
622
623
C < CREATE > to fiddle around with low-level workings.
623
624
624
- Another pattern of hooking into object construction is by writing your own
625
- C < BUILDALL > method. To make sure that initialization of superclasses works fine,
626
- you need to C < callsame > to invoke the parent classes C < BUILDALL > .
627
-
628
- = begin code
629
- class MyClass {
630
- method BUILDALL(|) {
631
- # initial things here
632
-
633
- callsame; # call the parent classes (or default) BUILDALL
634
-
635
- # you can do final checks here.
636
-
637
- self # return the fully built object
638
- }
639
- }
640
- = end code
641
-
642
625
The C < TWEAK > submethod allows you to check things or modify attributes after
643
626
object construction:
644
627
0 commit comments