BUILD called twice.

[email protected] (Bill Moseley)
Newsgroups perl.moose
Message-ID <CAKhN_m47X2Gxc=G2PXkjJ90L=t7mGtJ=gYYPhZsA_YnRw8ZeNg@mail.gmail.com>
Hi all,

I had a problem that I tracked down to BUILD getting run twice.

It turned out a subclass was (incorrectly) using "after 'BUILD'".   When
that happens the BUILD in the base class runs twice.

I realize it's an improper use of BUILD but just wanted to note it in case
it's not an expected behavior.

package baseclass;
use Moose;
sub BUILD { warn "in baseclass BUILD\n" }

package subclass;
use Moose;
extends 'baseclass';
# WRONG usage
after 'BUILD' => sub { warn "in bad subclass BUILD\n" };

package main;
subclass->new;

1;


Results in:

in baseclass BUILD
in baseclass BUILD
in bad subclass BUILD



 $Moose::VERSION = '2.0604';

-- 
Bill Moseley
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.