Re: How to call post-constructor automatically
[email protected] (Yuri Shtil)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Yuval Kogman wrote:
> On Thu, Oct 16, 2008 at 14:38:37 -0700, Yuri Shtil wrote:
>
>
>> The trick is I want the method be called implicitly as a part of new.
>> It is almost as having a hidden subclass of Two with a call to
>> post_constructor in its BUILD method.
>>
>
> I think this is exactly what you want,
>
> sub BUILD {
> shift->post_constructor;
> }
>
> in Two will work as you expect.
>
> That will be called even if a subclass adds another BUILD method,
> but of course 'post_constructor' will be overridable normally (i'm
> guessing that's why you don't want to just use BUILD?).
>
>
Thank you Yuval,
However I want to avoid putting the call into each BUILD that is the
last in the hierarchy. If I decide to subclass from Two, I have to move
the call manually. The idea behind my question is to be able to check if
all constructors worked "correctly", for example consumed all named
parameters.
--
Yuri