develooper Front page | perl.perl6.language | Postings from February 2012

Re: Setting private attributes during object build

Thread Previous | Thread Next
From:
Damian Conway
Date:
February 1, 2012 21:43
Subject:
Re: Setting private attributes during object build
Message ID:
CAATtAp5+OB=eSe-Mn=9Q_qDRVT39fW5KPTV6CO6GBXxFskb9cw@mail.gmail.com
Yary wrote:

> If one wants to use any argument in the constructor other than a
> public attribute (positional OR named other than an attribute name),
> one must define a "method new( ... )".

Huh? I know I've been out of the loop lately, but this seems fundamentally
wrong.

Constructor args certainly shouldn't be restricted to just the names
of public attributes. And one definitely shouldn't have to redeclare new()
just to allow for more sophisticated initialization. The whole point of having
BUILD() is to separate allocation concerns from initialization concerns.

S12 has an example that explicitly contradicts this constraint that constructor
args have to be public attribute names:

    submethod BUILD ($arg) {
        $.attr = $arg;
    }

Either I'm missing the point here (which is entirely possible ;-) or something
isn't right in the current semantics of object initialization.

Damian

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