From: Dave Rolsky Date: Fri, 5 Dec 2008 02:15:40 +0000 (+0000) Subject: If the constructor in a parent class has method modifiers, we will not X-Git-Tag: 0.62_02~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=817660201c58e0d4a697bfe2d0f65781622318d7;p=gitmo%2FMoose.git If the constructor in a parent class has method modifiers, we will not inline it. In that case, mention the fact that it is wrapped in the warning. --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 2357fe8..50b3bf2 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -79,9 +79,15 @@ sub can_be_inlined { my $class = $self->associated_metaclass->name; if ( $constructor->body != $expected_class->can('new') ) { - warn "Not inlining a constructor for $class since it is not" + my $warning + = "Not inlining a constructor for $class since it is not" . " inheriting the default $expected_class constructor\n"; + $warning .= " (constructor has method modifiers which would be lost if it were inlined)\n" + if $constructor->isa('Class::MOP::Method::Wrapped'); + + warn $warning; + return 0; } else { diff --git a/t/300_immutable/011_constructor_is_wrapped.t b/t/300_immutable/011_constructor_is_wrapped.t new file mode 100644 index 0000000..5b7ddfb --- /dev/null +++ b/t/300_immutable/011_constructor_is_wrapped.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +eval "use Test::Output"; +plan skip_all => "Test::Output is required for this test" if $@; + +plan tests => 1; + +{ + package ModdedNew; + use Moose; + + before 'new' => sub { }; +} + +{ + package Foo; + use Moose; + + extends 'ModdedNew'; + + ::stderr_is( + sub { Foo->meta->make_immutable }, + "Not inlining a constructor for Foo since it is not inheriting the default Moose::Object constructor\n (constructor has method modifiers which would be lost if it were inlined)\n", + 'got a warning that Foo may not have an inlined constructor' + ); +}