From 058f1be1e12a7ce1438702f9a88046c076cdb5a3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 28 May 2009 23:17:21 -0500 Subject: if a class satisfies all its requirements, restore the constructor --- lib/MooseX/ABC/Trait/Class.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/MooseX/ABC/Trait/Class.pm b/lib/MooseX/ABC/Trait/Class.pm index bca130f..b47bea0 100644 --- a/lib/MooseX/ABC/Trait/Class.pm +++ b/lib/MooseX/ABC/Trait/Class.pm @@ -9,7 +9,8 @@ has required_methods => ( default => sub { [] }, auto_deref => 1, provides => { - push => 'add_required_method', + push => 'add_required_method', + empty => 'has_required_methods', }, ); @@ -30,6 +31,18 @@ after _superclasses_updated => sub { } } } + + return if $self->has_required_methods; + + # at this point, the current class didn't have any required methods to + # start with, and all of the required methods from superclasses have + # been satisfied, so restore the constructor + + my $constructor = $self->find_method_by_name('new'); + if ($constructor->original_package_name eq 'MooseX::ABC::Role::Object') { + my $moose_constructor = Class::MOP::class_of('Moose::Object')->get_method('new'); + $self->add_method(new => $moose_constructor->clone); + } }; no Moose::Role; -- cgit v1.2.3-54-g00ecf