From: Matt S Trout Date: Mon, 14 Nov 2011 23:53:20 +0000 (+0000) Subject: fix $obj->new X-Git-Tag: v0.009012~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FRole-Tiny.git;a=commitdiff_plain;h=301616bb14d1924c20a5404100741b026ee8c04f fix $obj->new --- diff --git a/Changes b/Changes index a2aec8d..afaf3d1 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - make Method::Generate::Constructor handle $obj->new - fix bug where constants containing a reference weren't handled correctly (ref(\[]) is 'REF' not 'SCALAR', ref(\v1) is 'VSTRING') diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm index 11f0589..c11cbd2 100644 --- a/lib/Method/Generate/Constructor.pm +++ b/lib/Method/Generate/Constructor.pm @@ -42,7 +42,8 @@ sub generate_method { $spec->{$no_init}{init_arg} = $no_init; } local $self->{captures} = {}; - my $body = ' my $class = shift;'."\n"; + my $body = ' my $class = shift;'."\n" + .' $class = ref($class) if ref($class);'."\n"; $body .= $self->_handle_subconstructor($into, $name); my $into_buildargs = $into->can('BUILDARGS'); if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) { diff --git a/t/method-generate-constructor.t b/t/method-generate-constructor.t index 6a030c8..6299010 100644 --- a/t/method-generate-constructor.t +++ b/t/method-generate-constructor.t @@ -57,4 +57,10 @@ is( 'hashrefs also supported' ); +is( + exception { $first->new(one => 1, THREE => 3) }, + undef, + 'calling ->new on an object works' +); + done_testing;