From: Matt S Trout Date: Thu, 3 May 2007 19:00:13 +0000 (+0000) Subject: horrible hack to make immutability on Moose class extending Class::MOP class work X-Git-Tag: 0_21~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d66bea3c621556197965144bb85dd99f46e0fa59;p=gitmo%2FMoose.git horrible hack to make immutability on Moose class extending Class::MOP class work --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index fc1715e..c82ec6c 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -108,18 +108,20 @@ sub _generate_slot_initializer { my $attr = $self->attributes->[$index]; my @source = ('## ' . $attr->name); + + my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME - if ($attr->is_required && !$attr->has_default) { + if ($is_moose && $attr->is_required && !$attr->has_default) { push @source => ('(exists $params{\'' . $attr->init_arg . '\'}) ' . '|| confess "Attribute (' . $attr->name . ') is required";'); } - if ($attr->has_default && !$attr->is_lazy) { + if ($attr->has_default && !($is_moose &&$attr->is_lazy)) { push @source => 'if (exists $params{\'' . $attr->init_arg . '\'}) {'; push @source => ('my $val = $params{\'' . $attr->init_arg . '\'};'); - if ($attr->has_type_constraint) { + if ($is_moose && $attr->has_type_constraint) { push @source => ('my $type_constraint = $attrs->[' . $index . ']->type_constraint;'); if ($attr->should_coerce && $attr->type_constraint->has_coercion) { @@ -139,7 +141,7 @@ sub _generate_slot_initializer { $attr, ('$attrs->[' . $index . ']->type_constraint'), '$val' - ) if $attr->has_type_constraint; + ) if ($is_moose && $attr->has_type_constraint); push @source => $self->_generate_slot_assignment($attr, $default); push @source => "}"; @@ -148,7 +150,7 @@ sub _generate_slot_initializer { push @source => '(exists $params{\'' . $attr->init_arg . '\'}) && do {'; push @source => ('my $val = $params{\'' . $attr->init_arg . '\'};'); - if ($attr->has_type_constraint) { + if ($is_moose && $attr->has_type_constraint) { push @source => ('my $type_constraint = $attrs->[' . $index . ']->type_constraint;'); if ($attr->should_coerce && $attr->type_constraint->has_coercion) { @@ -173,8 +175,10 @@ sub _generate_slot_assignment { $value ) . ';' ); + + my $is_moose = $attr->isa('Moose::Meta::Attribute'); # XXX FIXME - if ($attr->is_weak_ref) { + if ($is_moose && $attr->is_weak_ref) { $source .= ( "\n" . $self->meta_instance->inline_weaken_slot_value( diff --git a/t/020_foreign_inheritence.t b/t/020_foreign_inheritence.t index ccf4a57..7ee39ba 100644 --- a/t/020_foreign_inheritence.t +++ b/t/020_foreign_inheritence.t @@ -60,4 +60,4 @@ is($foo_moose->no_moose, 'Elk', '... got the right value from the Elk method'); is($foo_moose->moose, 'Foo', '... got the right value from the Foo::Moose method'); lives_ok { Old::Bucket::Nose->meta->make_immutable(debug => 0); } - => 'Immutability on Moose class extending Class::MOP class ok'; + 'Immutability on Moose class extending Class::MOP class ok';