Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BUILD and other submethods

24 views
Skip to first unread message

Ingo Blechschmidt

unread,
May 16, 2005, 10:59:11 AM5/16/05
to perl6-l...@perl.org
Hi,

class Foo {
submethod BUILD() {
say 42;
}
}

class Bar is Foo {
submethod BUILD() {
say 23;
}
}

my Bar $bar .= new;

I suppose this will output:
42
23

S12 says that "submethod[s] [are] called only when a method call is
dispatched directly to the current class", but the default implementation of
"new" (as given by Object), calls BUILDALL, which in turn calls all BUILDs, so
I think both BUILDs are executed. Are they?

S12 says that "[s]ubmethods are for declaring infrastructural methods that
shouldn't be inherited by subclasses". I read this "shouldn't be inherited" as
that a submethod definition of the same name in a subclass does not
overwrite/substitute the definition of the parent class. Correct?


class A { submethod blarb() { say 42 } }
class B is A { submethod blarb() { say 23 } }
B.new.blarb;

Does this only output "23"? (I think so, as I don't call A::blarb explicitly.
If I wanted to call A's blarb, I'd have to say "B.new.A::blarb", correct?)


--Ingo
</lots_of_questions>

--
Linux, the choice of a GNU | self-reference, n. - See self-reference
generation on a dual AMD |
Athlon! |

Larry Wall

unread,
May 16, 2005, 11:48:29 AM5/16/05
to perl6-l...@perl.org
On Mon, May 16, 2005 at 02:59:11PM +0000, Ingo Blechschmidt wrote:
: Hi,
:
: class Foo {
: submethod BUILD() {
: say 42;
: }
: }
:
: class Bar is Foo {
: submethod BUILD() {
: say 23;
: }
: }
:
: my Bar $bar .= new;
:
: I suppose this will output:
: 42
: 23
:
: S12 says that "submethod[s] [are] called only when a method call is
: dispatched directly to the current class", but the default implementation of
: "new" (as given by Object), calls BUILDALL, which in turn calls all BUILDs, so
: I think both BUILDs are executed. Are they?

Yes.

: S12 says that "[s]ubmethods are for declaring infrastructural methods that

: shouldn't be inherited by subclasses". I read this "shouldn't be inherited" as
: that a submethod definition of the same name in a subclass does not
: overwrite/substitute the definition of the parent class. Correct?

Correct.

: class A { submethod blarb() { say 42 } }

: class B is A { submethod blarb() { say 23 } }
: B.new.blarb;
:
: Does this only output "23"? (I think so, as I don't call A::blarb explicitly.
: If I wanted to call A's blarb, I'd have to say "B.new.A::blarb", correct?)

Yes.

Larry

0 new messages