From: Shawn M Moore Date: Tue, 9 Dec 2008 04:44:50 +0000 (+0000) Subject: Only inline BUILDARGS if the class has one that isn't Mouse::Object's X-Git-Tag: 0.19~119 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=9dcd7d2378107301c0f815a407b3b4e55c2909f8 Only inline BUILDARGS if the class has one that isn't Mouse::Object's --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 4b5e099..82459c5 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -7,7 +7,7 @@ sub generate_constructor_method_inline { my @attrs = $meta->compute_all_applicable_attributes; my $buildall = $class->_generate_BUILDALL($meta); - my $buildargs = $class->_generate_BUILDARGS(); + my $buildargs = $class->_generate_BUILDARGS($meta); my $processattrs = $class->_generate_processattrs($meta, \@attrs); my $code = <<"..."; @@ -125,7 +125,14 @@ sub _generate_processattrs { } sub _generate_BUILDARGS { - <<'...'; + my $self = shift; + my $meta = shift; + + if ($meta->name->can('BUILDARGS') != Mouse::Object->can('BUILDARGS')) { + return '$class->BUILDARGS(@_)'; + } + + return <<'...'; do { if ( scalar @_ == 1 ) { if ( defined $_[0] ) { diff --git a/t/300_immutable/009_buildargs.t b/t/300_immutable/009_buildargs.t index c7c700c..5f9a10a 100644 --- a/t/300_immutable/009_buildargs.t +++ b/t/300_immutable/009_buildargs.t @@ -31,23 +31,13 @@ use Test::More tests => 14; foreach my $class qw(Foo Bar) { is( $class->new->bar, undef, "no args" ); is( $class->new( bar => 42 )->bar, 42, "normal args" ); - SKIP: { - skip "this feature doesn't supported by Mouse", 1; - is( $class->new( 37 )->bar, 37, "single arg" ); - }; - { - my $o = $class->new(bar => 42, baz => 47); - is($o->bar, 42, '... got the right bar'); - is($o->baz, 47, '... got the right bar'); - } - SKIP: { - skip "this feature doesn't supported by Mouse", 2; - { - my $o = $class->new(42, baz => 47); - is($o->bar, 42, '... got the right bar'); - is($o->baz, 47, '... got the right bar'); - } - }; + is( $class->new( 37 )->bar, 37, "single arg" ); + my $o = $class->new(bar => 42, baz => 47); + is($o->bar, 42, '... got the right bar'); + is($o->baz, 47, '... got the right bar'); + my $ob = $class->new(42, baz => 47); + is($ob->bar, 42, '... got the right bar'); + is($ob->baz, 47, '... got the right bar'); }