diff options
author | doy <doy@tozt.net> | 2009-04-10 02:06:27 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-04-10 02:06:27 -0500 |
commit | 32e195a50b6e424b333d1e2ac94852f0e4a40c8e (patch) | |
tree | ed6198fd72aff333c1cefa1da1d26626b70cdfa7 /lib | |
parent | c89ec958fc7dceb47e7f097ca76cce104e5dde77 (diff) | |
download | moosex-nonmoose-32e195a50b6e424b333d1e2ac94852f0e4a40c8e.tar.gz moosex-nonmoose-32e195a50b6e424b333d1e2ac94852f0e4a40c8e.zip |
aha - what i really need to be doing here is using normal method resolution to my advantage
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MooseX/NonMoose.pm | 32 |
1 files changed, 17 insertions, 15 deletions
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 { |