in reply to Re^3: Problem generating builder functions with Moose for inherited objects
in thread Problem generating builder functions with Moose for inherited objects

And right back at ya :)

From the Moose's mouth: http://search.cpan.org/~drolsky/Moose/lib/Moose/Manual/Construction.pod

The BUILD method is called after an object is created.
...
The interaction between multiple BUILD methods in an inheritance hierarchy is different from normal Perl methods. You should never call $self->SUPER::BUILD.
Moose arranges to have all of the BUILD methods in a hierarchy called when an object is constructed, from parents to children.

From which I concluded that first a parent object would be created and BUILD called, then the inheritance would kick in and the child's BUILD would be called.
Anyway, given the current situation, I'd need to dynamically figure out how $self relates to __PACKAGE__ and create the appropriate builder functions (if they don't exist already). Or something completely different.
  • Comment on Re^4: Problem generating builder functions with Moose for inherited objects

Replies are listed 'Best First'.
Re^5: Problem generating builder functions with Moose for inherited objects
by tospo (Hermit) on Sep 02, 2010 at 12:55 UTC

    Would it not be better to use proper Moose roles now that you are converting this to Moose? Otherwise I would really be wondering what you gain from the conversion? Sorry, I know you probably thought about all of this and I know it's a bit annoying when you ask a question and people start preaching "the one true path" at you but sometimes it may also helpful to run your reasoning past another person to arrive at new solutions...

    Anyway, I think the Moose documentation is not contradicting the observed (and probably expected) behaviour. Yes, the parent's BUILD method is called but the object is still of class "Child", not "Parent". It's like calling $self->SUPER::BUILD (which you shouldn't) - you call an inherited METHOD but the object you call it on doesn't change class, if that makes any sense?
    The fact that you get "Parent" from __PACKAGE__ doesn't mean that the object is of that class - it just means that this method is defined in the file that defines package "Parent".

      The idea was to use proper Moose roles, but I got sidetracked at the point where I used lazy_build=>1 and still had to generate builder-functions.

      I could fill you in on the details of the getup, but it would be inappropriate to do so in this thread.

      Besides that, your reasoning on $self rings true :)