From: Shawn M Moore Date: Thu, 5 Feb 2009 01:53:31 +0000 (+0000) Subject: Ensure that we're not blowing away an inherited constructor X-Git-Tag: 0.19~59 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c7a6403fce1a32c7e91c65691aae43bb00838501;p=gitmo%2FMouse.git Ensure that we're not blowing away an inherited constructor --- diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index afe9294..cd23c63 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -148,7 +148,14 @@ sub make_immutable { my %args = @_; my $name = $self->name; $self->{is_immutable}++; - $self->add_method('new' => Mouse::Meta::Method::Constructor->generate_constructor_method_inline( $self )); + + if ($self->name->can('new') != Mouse::Object->can('new')) { + warn "Not inlining a constructor for ".$self->name." since it is not inheriting the default Mouse::Object constructor\n"; + } + else { + $self->add_method('new' => Mouse::Meta::Method::Constructor->generate_constructor_method_inline( $self )); + } + if ($args{inline_destructor}) { $self->add_method('DESTROY' => Mouse::Meta::Method::Destructor->generate_destructor_method_inline( $self )); } diff --git a/t/040-existing-subclass.t b/t/040-existing-subclass.t new file mode 100644 index 0000000..fe63fad --- /dev/null +++ b/t/040-existing-subclass.t @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +BEGIN { + eval "use Test::Output;"; + plan skip_all => "Test::Output is required for this test" if $@; + plan tests => 1; +} + +do { + package Parent; + sub new { bless {}, shift } + + package Child; + BEGIN { our @ISA = 'Parent' } + use Mouse; +}; + +stderr_is( + sub { package Child; __PACKAGE__->meta->make_immutable }, + "Not inlining a constructor for Child since it is not inheriting the default Mouse::Object constructor\n", + 'Mouse warns when it would have blown away the inherited constructor', +); +