[Moose-commits] r7548 - in Mouse/trunk: lib/Mouse/Meta t

sartak at code2.0beta.co.uk sartak at code2.0beta.co.uk
Thu Feb 5 01:53:32 GMT 2009


Author: sartak
Date: 2009-02-04 17:53:31 -0800 (Wed, 04 Feb 2009)
New Revision: 7548

Added:
   Mouse/trunk/t/040-existing-subclass.t
Modified:
   Mouse/trunk/lib/Mouse/Meta/Class.pm
Log:
Ensure that we're not blowing away an inherited constructor

Modified: Mouse/trunk/lib/Mouse/Meta/Class.pm
===================================================================
--- Mouse/trunk/lib/Mouse/Meta/Class.pm	2009-02-05 01:53:24 UTC (rev 7547)
+++ Mouse/trunk/lib/Mouse/Meta/Class.pm	2009-02-05 01:53:31 UTC (rev 7548)
@@ -148,7 +148,14 @@
     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 ));
     }

Added: Mouse/trunk/t/040-existing-subclass.t
===================================================================
--- Mouse/trunk/t/040-existing-subclass.t	                        (rev 0)
+++ Mouse/trunk/t/040-existing-subclass.t	2009-02-05 01:53:31 UTC (rev 7548)
@@ -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',
+);
+




More information about the Moose-commits mailing list