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

Re: Setting delegated attributes in constructors

Thread Previous | Thread Next
From:
Harald.Joerg
Date:
February 13, 2018 16:27
Subject:
Re: Setting delegated attributes in constructors
Message ID:
87zi4clv8p.fsf@arcor.de
Merlyn Kline <merlyn@binary.co.uk> writes:

> I'd like to set delegated attributes in my object constructors
> (e.g. as below) but this doesn't seem to work.  Am I missing
> something?

perldoc Moose::Manual::Delegation calls it "Attribute delegation", but
actually you're not delegating attributes. Instead, you are delegating
method calls to an attribute of your class.

So this is what you are missing: Calling Class->new simply isn't calling
$object->thing underneath.  If you add MooseX::StrictConstructor to your
package Class, it will barf at you saying

   Found unknown attribute(s) init_arg passed to the constructor: thing

BUILD or BUILDARGS can help to achieve what you're trying to do.
--
Cheers,
haj

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