From: Yuval Kogman Date: Thu, 27 Apr 2006 22:26:41 +0000 (+0000) Subject: Nudge Moose slightly in the "right" direction for the new instance thing X-Git-Tag: 0_09_03~60 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a7a9c530352af387fd4fa0c0fddb0bcf377cfa0;p=gitmo%2FMoose.git Nudge Moose slightly in the "right" direction for the new instance thing --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 28194c7..472ae09 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -158,7 +158,7 @@ sub _process_options { } sub initialize_instance_slot { - my ($self, $class, $instance, $params) = @_; + my ($self, $instance, $params) = @_; my $init_arg = $self->init_arg(); # try to fetch the init arg from the %params ... my $val; @@ -197,6 +197,16 @@ sub initialize_instance_slot { } } +sub _gen_required_arg { + my ( $self, $attr_name, $arg ) = @_; + return sprintf 'defined(%s) || confess "Attribute (%s) is required, so cannot be set to undef";', $arg, $attr_name; +} + +sub _gen_coerce { + my ( $self, $attr_name, $arg ); + return sprintf '%s->type->type_constraint->coercion->coerce(%s)', $self->_gen_invocant, $arg; +} + sub generate_accessor_method { my ($self, $attr_name) = @_; my $value_name = $self->should_coerce ? '$val' : '$_[1]'; @@ -386,4 +396,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 4039af5..2fbe0ef 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -55,9 +55,9 @@ sub new_object { sub construct_instance { my ($class, %params) = @_; - my $instance = $params{'__INSTANCE__'} || {}; + my $instance = $params{'__INSTANCE__'} || $class->get_meta_instance->create_instance(); foreach my $attr ($class->compute_all_applicable_attributes()) { - $attr->initialize_instance_slot($class, $instance, \%params) + $attr->initialize_instance_slot($instance, \%params) } return $instance; } @@ -230,4 +230,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut