> Also, I have no idea what your parenthetical means.
Parenthetical indicate that I know default fires before the
initializer for the attribute, but that not all defaults for all
attributes will fire before any of the initializers. Currently, an
Attribute process not a class process.
> "Awkward and counter-intuitive" is very subjective and therefore not a
> compelling reason to change things; for example, people regularly seem to
> think
> that it is awkward and counter-intuitive not to override new() when coming
> from
> vanilla Perl 5 OO.
>
> In this particular case, the way Moose does things means that code related to
> a
> given attribute (default, etc.) only sees that particular attribute in a
> half-built state -- that is, each other attribute is either completely
> initialized or not at all. This means there's much less opportunity for your
> object to be exposed in an inconsistent state.
I don't see the logic in the term "inconsistent." I've showed the flow
defined in a sequential list in my original post, maybe you can
clarify why you feel such a flow is inconsistent. I'll go ahead and
show you what I wanted to do with this. I have a Class, it should
accept either a "company_id", or a hash of "attributes" if you provide
a company_id the attribute hash is lazy when it is needed. If you
provide a hash of company attributes, then the value is immediately
entered into the DB, and the company_id gets set appropriately:
has 'attr' => (
isa => 'HashRef'
, is => 'ro'
, lazy => 1
, predicate => '_has_attr'
, default => sub {
my $self = shift;
die "No company id" unless $self->_has_company;
# Get from db.
}
);
has 'company' => (
isa => 'Int'
, is => 'ro'
, predicate => '_has_company'
, default => sub {
my $self = shift;
die 'No attributes or company id' unless $self->_has_attr;
# Insert into DB
}
)
Anyway, it just seems very naturally that this should work. You're
explicitly providing non-defaults for some attributes, but they're
order is undefined until other attribute's get their defaults -- it
seems like the current method provides no gain whatsoever.
--
Evan Carroll - [email protected]
System Lord of the Internets
web: http://www.evancarroll.com
ph: 281.901.0011