From 32e195a50b6e424b333d1e2ac94852f0e4a40c8e Mon Sep 17 00:00:00 2001 From: doy Date: Fri, 10 Apr 2009 02:06:27 -0500 Subject: aha - what i really need to be doing here is using normal method resolution to my advantage --- lib/MooseX/NonMoose.pm | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/MooseX/NonMoose.pm b/lib/MooseX/NonMoose.pm index de2660a..b03c2cd 100644 --- a/lib/MooseX/NonMoose.pm +++ b/lib/MooseX/NonMoose.pm @@ -6,20 +6,6 @@ Moose::Exporter->setup_import_methods( with_caller => ['extends_nonmoose'], ); -sub constructor { - my $class = shift; - my $meta = Class::MOP::Class->initialize($class); - my $super_new = $meta->find_next_method_by_name('new'); - my $self = $super_new->execute($class, @_); - my $params = $class->BUILDARGS(@_); - my $moose_self = $meta->new_object( - __INSTANCE__ => $self, - %$params, - ); - $moose_self->BUILDALL($params); - return $moose_self; -} - sub extends_nonmoose { my $caller = shift; my @superclasses = @_; @@ -29,7 +15,23 @@ sub extends_nonmoose { Moose::extends($caller, @superclasses); - Class::MOP::Class->initialize($caller)->add_method(new => \&constructor); + my $meta = Class::MOP::Class->initialize($caller); + if ($meta->find_next_method_by_name('new')->body ne \&constructor) { + $meta->add_method(new => sub { + my $class = shift; + my $meta = Class::MOP::Class->initialize($class); + my $caller_meta = Class::MOP::Class->initialize($caller); + my $super_new = $caller_meta->find_next_method_by_name('new'); + my $self = $super_new->execute($class, @_); + my $params = $class->BUILDARGS(@_); + my $moose_self = $meta->new_object( + __INSTANCE__ => $self, + %$params, + ); + $moose_self->BUILDALL($params); + return $moose_self; + }); + } } sub init_meta { -- cgit v1.2.3-54-g00ecf