develooper Front page | perl.moose | Postings from April 2018

Re: BUILD and how to create a subclass object when creating a parent

Thread Previous | Thread Next
From:
Karen Etheridge
Date:
April 25, 2018 17:54
Subject:
Re: BUILD and how to create a subclass object when creating a parent
Message ID:
CAPJsHfAGoPRiW+aLSs3Hn8u534SWz0Uwzvb+smi0Cze+xXhtdQ@mail.gmail.com
I'm not sure you mean by create a subclass instance on creation of its
superclass. Are you intending to have the superclass object have an
attribute that holds an instance of the subclass?  Perhaps can you show a
diagram of what you intend your data to look like after construction is
complete?

On Mon, Apr 23, 2018 at 7:53 AM, Arjan Widlak - United Knowledge <
arjan@unitedknowledge.nl> wrote:

> Hi,
>
> I tried to use the BUILD method to create an instance of a subclass on
> creating an instance of the parent. This does not work and the
> documentation clearly explains why:
>
> http://search.cpan.org/dist/Moose/lib/Moose/Manual/Construct
> ion.pod#BUILD_and_parent_classes
>
> BUILD methods are called from parent to child and hence this triggers a
> loop.
>
> I am able to do this with the around method modifier, however I need to
> override the behaviour in the subclass. This is also seems error prone and
> bad practice.
>
> But if this cannot be done this way, how should it be done? How can I
> always create a subclass instance on creation of it's superclass?
>
> Kind regards,
>
> Arjan
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About