Em Qua, 2009-08-19 às 15:37 -0700, Kevan Benson escreveu:
> Should there not be a way to define object constructors with custom 
> signatures that can be usefully invoked like a normal constructor?

What's the problem with

method new(Str $timestamp) {
   self.SUPER::new(ts => strptime('...',$timestamp));
}

?

> Currently, defining a BUILD method for a class with a specific signature 
> doesn't seem to allow for the object to be invoked by new with that 
> signature and be correctly passed to the right BUILD method.  It seems a 
> whole chain of new -> bless -> BUILDALL -> BUILD would need to be 
> defined with specific signatures just to get a custom constructor.

BUILD allows you to tweaken the initialization of known attributes. Your
BUILD submethod will only receive then named arguments for the
attributes locally defined in your class.

The purpose of BUILD is *not* to provide alternative signatures to the
constructor.

> Two possible thoughts on how to achieve this were put forth in the 
> #perl6 discussion.  One, auto build the chain on definition of a BUILD 
> method, which was thought be some to be a bit too magical (me included, 
> even though it was my suggestion at first).  Alternatively, pass the 
> capture of arguments as supplied by new down the chain of initialization 
> methods so any that were defined as multi's can be called correctly by 
> multiple dispatch at the correct point.

The bless-BUILDALL-BUILD chain uses the positional arguments as the
candidate protoobjects that define additional parameters for the
builders. the named parameters are passed to each BUILD method for
initialization.

Again, if you want a custom signature for new, just write a custom new.

daniel

Reply via email to