From: Dave Rolsky Date: Thu, 4 Dec 2008 23:05:41 +0000 (+0000) Subject: Ok, I was getting a little wacky. X-Git-Tag: 0.62_02~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e4c7477b7d0e8126f2deffedff77214cce078c67;p=gitmo%2FMoose.git Ok, I was getting a little wacky. If our parent has inlined a constructor, then the child can too. It's that simple, since the assumption is that inlined constructors are specific to the class in which they're inlined, and are not meant to be inherited. --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 3ef9fad..57a1b7a 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -51,39 +51,22 @@ sub can_be_inlined { my $self = shift; my $metaclass = $self->associated_metaclass; - my $class = $self->associated_metaclass->name; - # If any of our parents have been made immutable, we are okay to - # inline our own method as long as the parent's constructor class - # is the same as $self. - for my $meta ( grep { $_->is_immutable } - map { ( ref $metaclass )->initialize($_) } - $metaclass->linearized_isa ) { + # inline our own new method. The assumption is that an inlined new + # method provided by a parent does not actually get used by + # children anyway. + for my $meta ( + grep { $_->is_immutable } + map { ( ref $metaclass )->initialize($_) } + $metaclass->linearized_isa + ) { my $transformer = $meta->get_immutable_transformer; - my $constructor = $transformer->inlined_constructor - or next; - - return 1 if ref $constructor eq ref $self; - - my $parent_name = $meta->name; - my $constructor_class = ref $constructor; - my $self_class = ref $self; - - # This case is fairly unlikely. In most normal cases, - # incompatibility between constructor classes will be caught - # by the code that fixes metaclass incompatibility in - # Moose::Meta::Class. However, if the parent passes a - # constructor_class directly to - # Parent->meta->make_immutable(), this could happen. - warn "Not inlining a constructor for $class. It has a parent class ($parent_name)" - . " which was inlined using $constructor_class, but $class is using $self_class\n"; - - return 0; + return 1 if $transformer->inlined_constructor; } if ( my $constructor = $metaclass->find_method_by_name( $self->name ) ) { - + my $class = $self->associated_metaclass->name; my $expected_class = $self->_expected_constructor_class; if ( $constructor->body != $expected_class->can('new') ) { diff --git a/t/300_immutable/010_constructor_is_not_moose.t b/t/300_immutable/010_constructor_is_not_moose.t index 72e1b7a..2852c55 100644 --- a/t/300_immutable/010_constructor_is_not_moose.t +++ b/t/300_immutable/010_constructor_is_not_moose.t @@ -98,7 +98,7 @@ isnt( ::stderr_is( sub { Subclass->meta->make_immutable }, - "Not inlining a constructor for Subclass. It has a parent class (CustomCons) which was inlined using My::Constructor, but Subclass is using Moose::Meta::Method::Constructor\n", + q{}, 'no warning when inheriting from a class that has already made itself immutable' ); }